hoauth2-1.3.0: Haskell OAuth2 authentication client

Safe Haskell | None
Language | Haskell2010

Network.OAuth.OAuth2.Internal

Contents

- Data Types
- Types Synonym
- URLs

Description

A simple OAuth2 Haskell binding. (This is supposed to be independent of the http client used.)

Synopsis

- data OAuth2 = OAuth2 {
  - oauthClientId :: Text
  - oauthClientSecret :: Text
  - oauthOAuthorizeEndpoint :: URI
  - oauthAccessTokenEndpoint :: URI
  - oauthCallback :: Maybe URI
  }
- newtype AccessToken = AccessToken {
  - atoken :: Text
  }
- newtype RefreshToken = RefreshToken {
  - rtoken :: Text
  }
- newtype IdToken = IdToken {
  - idtoken :: Text
  }
- newtype ExchangeToken = ExchangeToken {
  - extoken :: Text
  }
- data OAuth2Token = OAuth2Token {
  - accessToken :: AccessToken
  - refreshToken :: Maybe RefreshToken
  - expiresIn :: Maybe Int
  - tokenType :: Maybe Text
  - idToken :: Maybe IdToken
  }
- data OAuth2Error a = OAuth2Error {
  - error :: Either Text a
  - errorDescription :: Maybe Text
  - errorUri :: Maybe (URIRef Absolute)
  }
- parseOAuth2Error :: FromJSON err => ByteString -> OAuth2Error err
- type OAuth2Result err a = Either (OAuth2Error err) a
- type PostBody = [(ByteString, ByteString)]
- type QueryParams = [(ByteString, ByteString)]
- authorizationUrl :: OAuth2 -> URI
- accessTokenUrl :: OAuth2 -> ExchangeToken -> (URI, PostBody)
- accessTokenUrl' :: OAuth2 -> ExchangeToken -> Maybe Text -> (URI, PostBody)
- refreshAccessTokenUrl :: OAuth2 -> RefreshToken -> (URI, PostBody)
- appendAccessToken :: URIRef a -> AccessToken -> URIRef a
- 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

# Data Types

data OAuth2 Source #

Query Parameter Representation

Constructors

OAuth2 |

Fields

- oauthClientId :: Text
- oauthClientSecret :: Text
- oauthOAuthorizeEndpoint :: URI
- oauthAccessTokenEndpoint :: URI
- oauthCallback :: Maybe URI

Instances

Eq OAuth2 Source # |
Methods (==) :: OAuth2 -> OAuth2 -> Bool # (/=) :: OAuth2 -> OAuth2 -> Bool #
Show OAuth2 Source # |
Methods showsPrec :: Int -> OAuth2 -> ShowS # show :: OAuth2 -> String # showList :: [OAuth2] -> ShowS #

newtype AccessToken Source #

Constructors

AccessToken |

Fields

- atoken :: Text

Instances

Show AccessToken Source # |
Methods showsPrec :: Int -> AccessToken -> ShowS # show :: AccessToken -> String # showList :: [AccessToken] -> ShowS #
ToJSON AccessToken Source # |
Methods toJSON :: AccessToken -> Value # toEncoding :: AccessToken -> Encoding # toJSONList :: [AccessToken] -> Value # toEncodingList :: [AccessToken] -> Encoding #
FromJSON AccessToken Source # |
Methods parseJSON :: Value -> Parser AccessToken # parseJSONList :: Value -> Parser [AccessToken] #

newtype RefreshToken Source #

Constructors

RefreshToken |

Fields

- rtoken :: Text

Instances

Show RefreshToken Source # |
Methods showsPrec :: Int -> RefreshToken -> ShowS # show :: RefreshToken -> String # showList :: [RefreshToken] -> ShowS #
ToJSON RefreshToken Source # |
Methods toJSON :: RefreshToken -> Value # toEncoding :: RefreshToken -> Encoding # toJSONList :: [RefreshToken] -> Value # toEncodingList :: [RefreshToken] -> Encoding #
FromJSON RefreshToken Source # |
Methods parseJSON :: Value -> Parser RefreshToken # parseJSONList :: Value -> Parser [RefreshToken] #

newtype IdToken Source #

Constructors

IdToken |

Fields

- idtoken :: Text

Instances

Show IdToken Source # |
Methods showsPrec :: Int -> IdToken -> ShowS # show :: IdToken -> String # showList :: [IdToken] -> ShowS #
ToJSON IdToken Source # |
Methods toJSON :: IdToken -> Value # toEncoding :: IdToken -> Encoding # toJSONList :: [IdToken] -> Value # toEncodingList :: [IdToken] -> Encoding #
FromJSON IdToken Source # |
Methods parseJSON :: Value -> Parser IdToken # parseJSONList :: Value -> Parser [IdToken] #

newtype ExchangeToken Source #

Constructors

ExchangeToken |

Fields

- extoken :: Text

Instances

Show ExchangeToken Source # |
Methods showsPrec :: Int -> ExchangeToken -> ShowS # show :: ExchangeToken -> String # showList :: [ExchangeToken] -> ShowS #
ToJSON ExchangeToken Source # |
Methods toJSON :: ExchangeToken -> Value # toEncoding :: ExchangeToken -> Encoding # toJSONList :: [ExchangeToken] -> Value # toEncodingList :: [ExchangeToken] -> Encoding #
FromJSON ExchangeToken Source # |
Methods parseJSON :: Value -> Parser ExchangeToken # parseJSONList :: Value -> Parser [ExchangeToken] #

data OAuth2Token Source #

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

Constructors

OAuth2Token |

Fields

- accessToken :: AccessToken
- refreshToken :: Maybe RefreshToken
- expiresIn :: Maybe Int
- tokenType :: Maybe Text
- idToken :: Maybe IdToken

Instances

Show OAuth2Token Source # |
Methods showsPrec :: Int -> OAuth2Token -> ShowS # show :: OAuth2Token -> String # showList :: [OAuth2Token] -> ShowS #
Generic OAuth2Token Source # |
Associated Types type Rep OAuth2Token :: * -> * # Methods from :: OAuth2Token -> Rep OAuth2Token x # to :: Rep OAuth2Token x -> OAuth2Token #
ToJSON OAuth2Token Source # |
Methods toJSON :: OAuth2Token -> Value # toEncoding :: OAuth2Token -> Encoding # toJSONList :: [OAuth2Token] -> Value # toEncodingList :: [OAuth2Token] -> Encoding #
FromJSON OAuth2Token Source # | Parse JSON data into `OAuth2Token`
Methods parseJSON :: Value -> Parser OAuth2Token # parseJSONList :: Value -> Parser [OAuth2Token] #
type Rep OAuth2Token Source # |

type Rep OAuth2Token = D1 (MetaData "OAuth2Token" "Network.OAuth.OAuth2.Internal" "hoauth2-1.3.0-ET7zNcTR0QAF1UGg1WyD6x" False) (C1 (MetaCons "OAuth2Token" PrefixI True) ((:*:) ((:*:) (S1 (MetaSel (Just Symbol "accessToken") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 AccessToken)) (S1 (MetaSel (Just Symbol "refreshToken") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe RefreshToken)))) ((:*:) (S1 (MetaSel (Just Symbol "expiresIn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe Int))) ((:*:) (S1 (MetaSel (Just Symbol "tokenType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe Text))) (S1 (MetaSel (Just Symbol "idToken") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe IdToken)))))))

data OAuth2Error a Source #

Constructors

OAuth2Error |

Fields

- error :: Either Text a
- errorDescription :: Maybe Text
- errorUri :: Maybe (URIRef Absolute)

Instances

Eq a => Eq (OAuth2Error a) Source # |
Methods (==) :: OAuth2Error a -> OAuth2Error a -> Bool # (/=) :: OAuth2Error a -> OAuth2Error a -> Bool #
Show a => Show (OAuth2Error a) Source # |
Methods showsPrec :: Int -> OAuth2Error a -> ShowS # show :: OAuth2Error a -> String # showList :: [OAuth2Error a] -> ShowS #
Generic (OAuth2Error a) Source # |
Associated Types type Rep (OAuth2Error a) :: * -> * # Methods from :: OAuth2Error a -> Rep (OAuth2Error a) x # to :: Rep (OAuth2Error a) x -> OAuth2Error a #
ToJSON err => ToJSON (OAuth2Error err) Source # |
Methods toJSON :: OAuth2Error err -> Value # toEncoding :: OAuth2Error err -> Encoding # toJSONList :: [OAuth2Error err] -> Value # toEncodingList :: [OAuth2Error err] -> Encoding #
FromJSON err => FromJSON (OAuth2Error err) Source # |
Methods parseJSON :: Value -> Parser (OAuth2Error err) # parseJSONList :: Value -> Parser [OAuth2Error err] #
type Rep (OAuth2Error a) Source # |

type Rep (OAuth2Error a) = D1 (MetaData "OAuth2Error" "Network.OAuth.OAuth2.Internal" "hoauth2-1.3.0-ET7zNcTR0QAF1UGg1WyD6x" False) (C1 (MetaCons "OAuth2Error" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "error") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Either Text a))) ((:*:) (S1 (MetaSel (Just Symbol "errorDescription") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe Text))) (S1 (MetaSel (Just Symbol "errorUri") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe (URIRef Absolute)))))))

parseOAuth2Error :: FromJSON err => ByteString -> OAuth2Error err Source #

# Types Synonym

type OAuth2Result err a = Either (OAuth2Error err) a Source #

Is either `Left` containing an error or `Right` containg a result

type PostBody = [(ByteString, ByteString)] Source #

type synonym of post body content

type QueryParams = [(ByteString, ByteString)] Source #

# URLs

authorizationUrl :: OAuth2 -> URI Source #

Prepare the authorization URL. Redirect to this URL asking for user interactive authentication.

accessTokenUrl Source #

Arguments

:: OAuth2 |
-> ExchangeToken | access code gained via authorization URL
-> (URI, PostBody) | access token request URL plus the request body.

Prepare the URL and the request body query for fetching an access token.

accessTokenUrl' Source #

Arguments

:: OAuth2 |
-> ExchangeToken | access code gained via authorization URL
-> Maybe Text | Grant Type
-> (URI, PostBody) | access token request URL plus the request body.

Prepare the URL and the request body query for fetching an access token, with optional grant type.

refreshAccessTokenUrl Source #

Arguments

:: OAuth2 |
-> RefreshToken | refresh token gained via authorization URL
-> (URI, PostBody) | refresh token request URL plus the request body.

Using a Refresh Token. Obtain a new access token by sending a refresh token to the Authorization server.

appendAccessToken Source #

Arguments

:: URIRef a | Base URI
-> AccessToken | Authorized Access Token
-> URIRef a | Combined Result

For `GET` method API.

accessTokenToParam :: AccessToken -> [(ByteString, ByteString)] Source #

Create `QueryParams` with given access token value.

appendQueryParams :: [(ByteString, ByteString)] -> URIRef a -> URIRef a Source #

uriToRequest :: MonadThrow m => URI -> m Request Source #

requestToUri :: Request -> URI Source #

hostLens :: Lens' Request ByteString Source #

portLens :: Lens' Request Int Source #