-- 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:
--   
--   
--   
- Google:
--   https://developers.google.com/accounts/docs/OAuth2WebServer
--   
- Github: http://developer.github.com/v3/oauth/
--   
- Facebook:
--   http://developers.facebook.com/docs/facebook-login/
--   
- Fitbit: http://dev.fitbit.com/docs/oauth2/
--   
- StackExchange:
--   https://api.stackexchange.com/docs/authentication
--   
- DropBox:
--   https://www.dropbox.com/developers/reference/oauth-guide
--   
- Weibo: http://open.weibo.com/wiki/Oauth2
--   
- Douban:
--   http://developers.douban.com/wiki/?title=oauth2
--   
@package hoauth2
@version 1.3.0

module Network.OAuth.OAuth2.TokenRequest

-- | Token Error Responses
--   https://tools.ietf.org/html/rfc6749#section-5.2
data Errors
InvalidRequest :: Errors
InvalidClient :: Errors
InvalidGrant :: Errors
UnauthorizedClient :: Errors
UnsupportedGrantType :: Errors
InvalidScope :: Errors
instance GHC.Generics.Generic Network.OAuth.OAuth2.TokenRequest.Errors
instance GHC.Classes.Eq Network.OAuth.OAuth2.TokenRequest.Errors
instance GHC.Show.Show Network.OAuth.OAuth2.TokenRequest.Errors
instance Data.Aeson.Types.FromJSON.FromJSON Network.OAuth.OAuth2.TokenRequest.Errors
instance Data.Aeson.Types.ToJSON.ToJSON Network.OAuth.OAuth2.TokenRequest.Errors

-- | 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 :: Text -> Text -> URI -> URI -> Maybe URI -> OAuth2
[oauthClientId] :: OAuth2 -> Text
[oauthClientSecret] :: OAuth2 -> Text
[oauthOAuthorizeEndpoint] :: OAuth2 -> URI
[oauthAccessTokenEndpoint] :: OAuth2 -> URI
[oauthCallback] :: OAuth2 -> Maybe URI
newtype AccessToken
AccessToken :: Text -> AccessToken
[atoken] :: AccessToken -> Text
newtype RefreshToken
RefreshToken :: Text -> RefreshToken
[rtoken] :: RefreshToken -> Text
newtype IdToken
IdToken :: Text -> IdToken
[idtoken] :: IdToken -> Text
newtype ExchangeToken
ExchangeToken :: Text -> ExchangeToken
[extoken] :: ExchangeToken -> Text

-- | The gained Access Token. Use Data.Aeson.decode to decode
--   string to AccessToken. The refreshToken is special
--   in some cases, e.g.
--   https://developers.google.com/accounts/docs/OAuth2
data OAuth2Token
OAuth2Token :: AccessToken -> Maybe RefreshToken -> Maybe Int -> Maybe Text -> Maybe IdToken -> OAuth2Token
[accessToken] :: OAuth2Token -> AccessToken
[refreshToken] :: OAuth2Token -> Maybe RefreshToken
[expiresIn] :: OAuth2Token -> Maybe Int
[tokenType] :: OAuth2Token -> Maybe Text
[idToken] :: OAuth2Token -> Maybe IdToken

-- | Parse JSON data into OAuth2Token
data OAuth2Error a
OAuth2Error :: Either Text a -> Maybe Text -> Maybe (URIRef Absolute) -> OAuth2Error a
[error] :: OAuth2Error a -> Either Text a
[errorDescription] :: OAuth2Error a -> Maybe Text
[errorUri] :: OAuth2Error a -> Maybe (URIRef Absolute)
parseOAuth2Error :: FromJSON err => ByteString -> OAuth2Error err

-- | Is either Left containing an error or Right containg a
--   result
type OAuth2Result err a = Either (OAuth2Error err) a

-- | type synonym of post body content
type PostBody = [(ByteString, ByteString)]
type QueryParams = [(ByteString, 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 -> ExchangeToken -> (URI, PostBody)

-- | Prepare the URL and the request body query for fetching an access
--   token, with optional grant type.
accessTokenUrl' :: OAuth2 -> ExchangeToken -> Maybe Text -> (URI, PostBody)

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

-- | For GET method API.
appendAccessToken :: URIRef a -> AccessToken -> URIRef a

-- | Create QueryParams with given access token value.
accessTokenToParam :: AccessToken -> [(ByteString, ByteString)]
appendQueryParams :: [(ByteString, ByteString)] -> URIRef a -> URIRef a
uriToRequest :: MonadThrow m => URI -> m Request
requestToUri :: Request -> URI
hostLens :: Lens' Request ByteString
portLens :: Lens' Request Int
instance GHC.Generics.Generic (Network.OAuth.OAuth2.Internal.OAuth2Error a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Network.OAuth.OAuth2.Internal.OAuth2Error a)
instance GHC.Show.Show a => GHC.Show.Show (Network.OAuth.OAuth2.Internal.OAuth2Error a)
instance GHC.Generics.Generic Network.OAuth.OAuth2.Internal.OAuth2Token
instance GHC.Show.Show Network.OAuth.OAuth2.Internal.OAuth2Token
instance Data.Aeson.Types.ToJSON.ToJSON Network.OAuth.OAuth2.Internal.ExchangeToken
instance Data.Aeson.Types.FromJSON.FromJSON Network.OAuth.OAuth2.Internal.ExchangeToken
instance GHC.Show.Show Network.OAuth.OAuth2.Internal.ExchangeToken
instance Data.Aeson.Types.ToJSON.ToJSON Network.OAuth.OAuth2.Internal.IdToken
instance Data.Aeson.Types.FromJSON.FromJSON Network.OAuth.OAuth2.Internal.IdToken
instance GHC.Show.Show Network.OAuth.OAuth2.Internal.IdToken
instance Data.Aeson.Types.ToJSON.ToJSON Network.OAuth.OAuth2.Internal.RefreshToken
instance Data.Aeson.Types.FromJSON.FromJSON Network.OAuth.OAuth2.Internal.RefreshToken
instance GHC.Show.Show Network.OAuth.OAuth2.Internal.RefreshToken
instance Data.Aeson.Types.ToJSON.ToJSON Network.OAuth.OAuth2.Internal.AccessToken
instance Data.Aeson.Types.FromJSON.FromJSON Network.OAuth.OAuth2.Internal.AccessToken
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.FromJSON.FromJSON Network.OAuth.OAuth2.Internal.OAuth2Token
instance Data.Aeson.Types.ToJSON.ToJSON Network.OAuth.OAuth2.Internal.OAuth2Token
instance Data.Aeson.Types.FromJSON.FromJSON err => Data.Aeson.Types.FromJSON.FromJSON (Network.OAuth.OAuth2.Internal.OAuth2Error err)
instance Data.Aeson.Types.ToJSON.ToJSON err => Data.Aeson.Types.ToJSON.ToJSON (Network.OAuth.OAuth2.Internal.OAuth2Error err)

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

-- | Request (via POST method) "OAuth2 Token".
fetchAccessToken :: Manager -> OAuth2 -> ExchangeToken -> IO (OAuth2Result Errors OAuth2Token)

-- | Request a new AccessToken with the Refresh Token. TODO: seems more
--   approporate to rename to refreshAccessToken
fetchRefreshToken :: Manager -> OAuth2 -> RefreshToken -> IO (OAuth2Result Errors OAuth2Token)

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

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

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

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

-- | Conduct an authorized GET request.
authGetBS :: FromJSON err => Manager -> AccessToken -> URI -> IO (OAuth2Result err ByteString)

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

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

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

-- | Conduct POST request with access token in the request body rather
--   header
authPostBS' :: FromJSON err => Manager -> AccessToken -> URI -> PostBody -> IO (OAuth2Result err ByteString)

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

-- | Parses a Response to to OAuth2Result
handleResponse :: FromJSON err => Response ByteString -> OAuth2Result err ByteString

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

-- | Try parseResponseJSON and parseResponseString
parseResponseFlexible :: FromJSON err => FromJSON a => OAuth2Result err ByteString -> OAuth2Result err a

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

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

module Network.OAuth.OAuth2.AuthorizationRequest

-- | Authorization Code Grant Error Responses
--   https://tools.ietf.org/html/rfc6749#section-4.1.2.1 Implicit
--   Grant Error Responses
--   https://tools.ietf.org/html/rfc6749#section-4.2.2.1
data Errors
InvalidRequest :: Errors
UnauthorizedClient :: Errors
AccessDenied :: Errors
UnsupportedResponseType :: Errors
InvalidScope :: Errors
ServerError :: Errors
TemporarilyUnavailable :: Errors
instance GHC.Generics.Generic Network.OAuth.OAuth2.AuthorizationRequest.Errors
instance GHC.Classes.Eq Network.OAuth.OAuth2.AuthorizationRequest.Errors
instance GHC.Show.Show Network.OAuth.OAuth2.AuthorizationRequest.Errors
instance Data.Aeson.Types.FromJSON.FromJSON Network.OAuth.OAuth2.AuthorizationRequest.Errors
instance Data.Aeson.Types.ToJSON.ToJSON Network.OAuth.OAuth2.AuthorizationRequest.Errors

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