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


-- | hoauth2
--   
--   Haskell OAuth2 authentication.
--   
--   Tested following services
--   
--   <ul>
--   <li>google web oauth:
--   <a>https://developers.google.com/accounts/docs/OAuth2WebServer</a></li>
--   <li>weibo oauth2: <a>http://open.weibo.com/wiki/Oauth2</a></li>
--   <li>github oauth: <a>http://developer.github.com/v3/oauth/</a></li>
--   </ul>
@package hoauth2
@version 0.4.2


-- | 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 <tt>Data.Aeson.decode</tt> to decode
--   string to <tt>AccessToken</tt>. The <tt>refresheToken</tt> is special
--   at some case. e.g.
--   https:<i></i>developers.google.com<i>accounts</i>docs/OAuth2
data AccessToken
AccessToken :: ByteString -> Maybe ByteString -> AccessToken
accessToken :: AccessToken -> ByteString
refreshToken :: AccessToken -> Maybe ByteString

-- | 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 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 <tt>?</tt>
appendQueryParam :: URI -> QueryParams -> URI

-- | Append query parameters with <tt>&amp;</tt>. appendQueryParam' :: URI
--   -&gt; QueryParams -&gt; URI appendQueryParam' uri q = uri
--   <a>append</a> <a>&amp;</a> <a>append</a> renderSimpleQuery False q
--   
--   For GET method API.
appendAccessToken :: URI -> AccessToken -> URI

-- | Create QueryParams with given access token value.
--   
--   accessTokenToParam :: BS.ByteString -&gt; QueryParams
--   accessTokenToParam token = [(<a>access_token</a>, token)]
accessTokenToParam :: AccessToken -> QueryParams

-- | lift value in the Maybe and abonda Nothing
transform' :: [(a, Maybe b)] -> [(a, b)]
instance Show OAuth2
instance Eq OAuth2
instance Show AccessToken
instance FromJSON AccessToken


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

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

-- | Request the <a>Refresh Token</a>.
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)

-- | 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.
authenticatedRequest :: Manager -> AccessToken -> StdMethod -> Request -> IO (Response ByteString)

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

-- | 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 : hoauth2 + accept :
--   application/json + authorization : Bearer xxxxx if AccessToken
--   provided.
updateRequestHeaders :: Maybe AccessToken -> Request -> Request

module Network.OAuth.OAuth2
