-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | hoauth2
--   
--   Haskell OAuth2 authentication.
--   
--   Tested following services
--   
--   
--   
- google web oauth:
--   https://developers.google.com/accounts/docs/OAuth2WebServer
--   
- github oauth: http://developer.github.com/v3/oauth/
--   
- facebook
--   
- fitbit
--   
- weibo oauth2: http://open.weibo.com/wiki/Oauth2
--   
- douban http://developers.douban.com/wiki/?title=oauth2
--   
@package hoauth2
@version 0.5.0

-- | A simple OAuth2 Haskell binding. (This is supposed to be independent
--   with http client.)
module Network.OAuth.OAuth2.Internal

-- | Query Parameter Representation
data OAuth2
OAuth2 :: ByteString -> ByteString -> ByteString -> ByteString -> Maybe ByteString -> OAuth2
[oauthClientId] :: OAuth2 -> ByteString
[oauthClientSecret] :: OAuth2 -> ByteString
[oauthOAuthorizeEndpoint] :: OAuth2 -> ByteString
[oauthAccessTokenEndpoint] :: OAuth2 -> ByteString
[oauthCallback] :: OAuth2 -> Maybe ByteString

-- | The gained Access Token. Use Data.Aeson.decode to decode
--   string to AccessToken. The refresheToken is special
--   at some case. e.g.
--   https://developers.google.com/accounts/docs/OAuth2
data AccessToken
AccessToken :: ByteString -> Maybe ByteString -> Maybe Int -> Maybe ByteString -> AccessToken
[accessToken] :: AccessToken -> ByteString
[refreshToken] :: AccessToken -> Maybe ByteString
[expiresIn] :: AccessToken -> Maybe Int
[tokenType] :: AccessToken -> Maybe ByteString

-- | Parse JSON data into {AccessToken}

-- | Is either Left containing an error or Right containg a
--   result
type OAuth2Result a = Either ByteString a

-- | type synonym of query parameters
type QueryParams = [(ByteString, ByteString)]

-- | type synonym of post body content
type PostBody = [(ByteString, ByteString)]

-- | type synonym of a URI
type URI = ByteString

-- | Prepare the authorization URL. Redirect to this URL asking for user
--   interactive authentication.
authorizationUrl :: OAuth2 -> URI

-- | Prepare URL and the request body query for fetching access token.
accessTokenUrl :: OAuth2 -> ByteString -> (URI, PostBody)
accessTokenUrl' :: OAuth2 -> ByteString -> Maybe ByteString -> (URI, PostBody)

-- | Using a Refresh Token. obtain a new access token by sending a refresh
--   token to the Authorization server.
refreshAccessTokenUrl :: OAuth2 -> ByteString -> (URI, PostBody)

-- | Append query parameters with ?
appendQueryParam :: URI -> QueryParams -> URI

-- | Append query parameters with &. appendQueryParam' :: URI
--   -> QueryParams -> URI appendQueryParam' uri q = uri
--   append "&" append renderSimpleQuery False q
--   
--   For GET method API.
appendAccessToken :: URI -> AccessToken -> URI

-- | Create QueryParams with given access token value.
--   
--   accessTokenToParam :: BS.ByteString -> QueryParams
--   accessTokenToParam token = [("access_token", token)]
accessTokenToParam :: AccessToken -> QueryParams

-- | lift value in the Maybe and abonda Nothing
transform' :: [(a, Maybe b)] -> [(a, b)]
instance GHC.Show.Show Network.OAuth.OAuth2.Internal.AccessToken
instance GHC.Classes.Eq Network.OAuth.OAuth2.Internal.OAuth2
instance GHC.Show.Show Network.OAuth.OAuth2.Internal.OAuth2
instance Data.Aeson.Types.Class.FromJSON Network.OAuth.OAuth2.Internal.AccessToken

-- | A simple http client to request OAuth2 tokens and several utils.
module Network.OAuth.OAuth2.HttpClient

-- | Request (via POST method) "Access Token".
fetchAccessToken :: Manager -> OAuth2 -> ByteString -> IO (OAuth2Result AccessToken)

-- | Request the "Refresh Token".
fetchRefreshToken :: Manager -> OAuth2 -> ByteString -> IO (OAuth2Result AccessToken)

-- | Conduct post request and return response as JSON.
doJSONPostRequest :: FromJSON a => Manager -> OAuth2 -> URI -> PostBody -> IO (OAuth2Result a)

-- | Conduct post request.
doSimplePostRequest :: Manager -> OAuth2 -> URI -> PostBody -> IO (OAuth2Result ByteString)

-- | Conduct GET request and return response as JSON.
authGetJSON :: FromJSON a => Manager -> AccessToken -> URI -> IO (OAuth2Result a)

-- | Conduct GET request.
authGetBS :: Manager -> AccessToken -> URI -> IO (OAuth2Result ByteString)

-- | same to authGetBS but set access token to query parameter
--   rather than header
authGetBS' :: Manager -> AccessToken -> URI -> IO (OAuth2Result ByteString)

-- | Conduct POST request and return response as JSON.
authPostJSON :: FromJSON a => Manager -> AccessToken -> URI -> PostBody -> IO (OAuth2Result a)

-- | Conduct POST request.
authPostBS :: Manager -> AccessToken -> URI -> PostBody -> IO (OAuth2Result ByteString)

-- | Sends a HTTP request including the Authorization header with the
--   specified access token.
authRequest :: Request -> (Request -> Request) -> Manager -> IO (OAuth2Result ByteString)
authRequest' :: Request -> (Request -> Request) -> Manager -> IO (Response ByteString)

-- | Parses a Response to to OAuth2Result
handleResponse :: Response ByteString -> OAuth2Result ByteString

-- | Parses a OAuth2Result BSL.ByteString into FromJSON a
--   => a
parseResponseJSON :: FromJSON a => OAuth2Result ByteString -> OAuth2Result a

-- | set several header values. + userAgennt : hoauth2 + accept :
--   application/json + authorization : Bearer xxxxx if AccessToken
--   provided.
updateRequestHeaders :: Maybe AccessToken -> Request -> Request

-- | Sets the HTTP method to use
setMethod :: StdMethod -> Request -> Request

module Network.OAuth.OAuth2
