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


-- | Haskell OAuth2 authentication client
--   
--   Haskell OAuth2 authentication client. Tested with the following
--   services:
--   
--   <ul>
--   <li>Google web:
--   <a>https://developers.google.com/accounts/docs/OAuth2WebServer</a></li>
--   <li>Github: <a>http://developer.github.com/v3/oauth/</a></li>
--   <li>Facebook:
--   <a>http://developers.facebook.com/docs/facebook-login/</a></li>
--   <li>Fitbit: <a>http://dev.fitbit.com/docs/oauth2/</a></li>
--   <li>Weibo: <a>http://open.weibo.com/wiki/Oauth2</a></li>
--   <li>Douban:
--   <a>http://developers.douban.com/wiki/?title=oauth2</a></li>
--   </ul>
@package hoauth2
@version 0.5.4.0


-- | A simple OAuth2 Haskell binding. (This is supposed to be independent
--   of the http client used.)
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 <tt>Data.Aeson.decode</tt> to decode
--   string to <tt>AccessToken</tt>. The <tt>refreshToken</tt> is special
--   in some cases, e.g.
--   <a>https://developers.google.com/accounts/docs/OAuth2</a>
data AccessToken
AccessToken :: ByteString -> Maybe ByteString -> Maybe Int -> Maybe ByteString -> Maybe ByteString -> AccessToken
[accessToken] :: AccessToken -> ByteString
[refreshToken] :: AccessToken -> Maybe ByteString
[expiresIn] :: AccessToken -> Maybe Int
[tokenType] :: AccessToken -> Maybe ByteString
[idToken] :: AccessToken -> Maybe ByteString

-- | Parse JSON data into <a>AccessToken</a>

-- | Is either <a>Left</a> containing an error or <a>Right</a> 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 the URL and the request body query for fetching an access
--   token.
accessTokenUrl :: OAuth2 -> ByteString -> (URI, PostBody)

-- | Prepare the URL and the request body query for fetching an access
--   token, with optional grant type.
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 using `"?"` or `"&amp;"`.
appendQueryParam :: URI -> QueryParams -> URI

-- | For <tt>GET</tt> method API.
appendAccessToken :: URI -> AccessToken -> URI

-- | Create <a>QueryParams</a> with given access token value.
accessTokenToParam :: AccessToken -> QueryParams

-- | Lift value in the <a>Maybe</a> and abandon <a>Nothing</a>.
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 <a>authGetBS</a> 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)

-- | Send an HTTP request including the Authorization header with the
--   specified access token.
authRequest :: Request -> (Request -> Request) -> Manager -> IO (OAuth2Result ByteString)

-- | Parses a <tt>Response</tt> to to <tt>OAuth2Result</tt>
handleResponse :: Response ByteString -> OAuth2Result ByteString

-- | Parses a <tt>OAuth2Result BSL.ByteString</tt> into <tt>FromJSON a
--   =&gt; a</tt>
parseResponseJSON :: FromJSON a => OAuth2Result ByteString -> OAuth2Result a

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

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


-- | A lightweight oauth2 haskell binding.
module Network.OAuth.OAuth2
