hoauth2-2.10.0: Haskell OAuth2 authentication client

Safe Haskell | Safe-Inferred
Language | Haskell2010

Network.OAuth.OAuth2

Contents

- OAuth2 Configuration
- Tokens
- Client Authentication methods
- Utilies for Request and URI
- Authorization Requset
- Token Request
- OAuth'ed http client utilities

Description

A lightweight oauth2 Haskell binding. See Readme for more details

Synopsis

- data OAuth2 = OAuth2 {
  - oauth2ClientId :: Text
  - oauth2ClientSecret :: Text
  - oauth2AuthorizeEndpoint :: URIRef Absolute
  - oauth2TokenEndpoint :: URIRef Absolute
  - oauth2RedirectUri :: URIRef Absolute
  }
- 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 ClientAuthenticationMethod
  - = ClientSecretBasic
  - | ClientSecretPost
  - | ClientAssertionJwt
- type PostBody = [(ByteString, ByteString)]
- type QueryParams = [(ByteString, ByteString)]
- defaultRequestHeaders :: [(HeaderName, 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
- authorizationUrl :: OAuth2 -> URI
- authorizationUrlWithParams :: QueryParams -> OAuth2 -> URI
- module Network.OAuth.OAuth2.TokenRequest
- module Network.OAuth.OAuth2.HttpClient

# OAuth2 Configuration

data OAuth2 Source #

Query Parameter Representation

Constructors

OAuth2 |

Fields

- oauth2ClientId :: Text
- oauth2ClientSecret :: Text
- oauth2AuthorizeEndpoint :: URIRef Absolute
- oauth2TokenEndpoint :: URIRef Absolute
- oauth2RedirectUri :: URIRef Absolute

#### Instances

Instances details

Show OAuth2 Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods showsPrec :: Int -> OAuth2 -> ShowS Source # show :: OAuth2 -> String Source # showList :: [OAuth2] -> ShowS Source #
Default OAuth2 Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods def :: OAuth2 #
Eq OAuth2 Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods (==) :: OAuth2 -> OAuth2 -> Bool Source # (/=) :: OAuth2 -> OAuth2 -> Bool Source #

# Tokens

newtype AccessToken Source #

Constructors

AccessToken |

Fields

- atoken :: Text

#### Instances

Instances details

FromJSON AccessToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods parseJSON :: Value -> Parser AccessToken Source # parseJSONList :: Value -> Parser [AccessToken] Source #
ToJSON AccessToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods toJSON :: AccessToken -> Value Source # toEncoding :: AccessToken -> Encoding Source # toJSONList :: [AccessToken] -> Value Source # toEncodingList :: [AccessToken] -> Encoding Source #
Show AccessToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods showsPrec :: Int -> AccessToken -> ShowS Source # show :: AccessToken -> String Source # showList :: [AccessToken] -> ShowS Source #
Binary AccessToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods put :: AccessToken -> Put Source # get :: Get AccessToken Source # putList :: [AccessToken] -> Put Source #
Eq AccessToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods (==) :: AccessToken -> AccessToken -> Bool Source # (/=) :: AccessToken -> AccessToken -> Bool Source #

newtype RefreshToken Source #

Constructors

RefreshToken |

Fields

- rtoken :: Text

#### Instances

Instances details

FromJSON RefreshToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods parseJSON :: Value -> Parser RefreshToken Source # parseJSONList :: Value -> Parser [RefreshToken] Source #
ToJSON RefreshToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods toJSON :: RefreshToken -> Value Source # toEncoding :: RefreshToken -> Encoding Source # toJSONList :: [RefreshToken] -> Value Source # toEncodingList :: [RefreshToken] -> Encoding Source #
Show RefreshToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods showsPrec :: Int -> RefreshToken -> ShowS Source # show :: RefreshToken -> String Source # showList :: [RefreshToken] -> ShowS Source #
Binary RefreshToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods put :: RefreshToken -> Put Source # get :: Get RefreshToken Source # putList :: [RefreshToken] -> Put Source #
Eq RefreshToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods (==) :: RefreshToken -> RefreshToken -> Bool Source # (/=) :: RefreshToken -> RefreshToken -> Bool Source #
ToQueryParam RefreshToken Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: RefreshToken -> Map Text Text Source #

newtype IdToken Source #

Constructors

IdToken |

Fields

- idtoken :: Text

#### Instances

Instances details

FromJSON IdToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods parseJSON :: Value -> Parser IdToken Source # parseJSONList :: Value -> Parser [IdToken] Source #
ToJSON IdToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods toJSON :: IdToken -> Value Source # toEncoding :: IdToken -> Encoding Source # toJSONList :: [IdToken] -> Value Source # toEncodingList :: [IdToken] -> Encoding Source #
Show IdToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods showsPrec :: Int -> IdToken -> ShowS Source # show :: IdToken -> String Source # showList :: [IdToken] -> ShowS Source #
Binary IdToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods put :: IdToken -> Put Source # get :: Get IdToken Source # putList :: [IdToken] -> Put Source #
Eq IdToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods (==) :: IdToken -> IdToken -> Bool Source # (/=) :: IdToken -> IdToken -> Bool Source #

newtype ExchangeToken Source #

Authorization Code

Constructors

ExchangeToken |

Fields

- extoken :: Text

#### Instances

Instances details

FromJSON ExchangeToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods parseJSON :: Value -> Parser ExchangeToken Source # parseJSONList :: Value -> Parser [ExchangeToken] Source #
ToJSON ExchangeToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods toJSON :: ExchangeToken -> Value Source # toEncoding :: ExchangeToken -> Encoding Source # toJSONList :: [ExchangeToken] -> Value Source # toEncodingList :: [ExchangeToken] -> Encoding Source #
Show ExchangeToken Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods showsPrec :: Int -> ExchangeToken -> ShowS Source # show :: ExchangeToken -> String Source # showList :: [ExchangeToken] -> ShowS Source #
ToQueryParam ExchangeToken Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: ExchangeToken -> Map Text Text Source #

data OAuth2Token Source #

https://www.rfc-editor.org/rfc/rfc6749#section-4.1.4

Constructors

OAuth2Token |

Fields

- accessToken :: AccessToken
- refreshToken :: Maybe RefreshToken

  Exists when `offline_access` scope is in the Authorization Request and the provider supports Refresh Access Token.

- expiresIn :: Maybe Int
- tokenType :: Maybe Text

  See https://www.rfc-editor.org/rfc/rfc6749#section-5.1. It's required per spec. But OAuth2 provider implementation are vary. Maybe will remove `Maybe` in future release.

- idToken :: Maybe IdToken

  Exists when `openid` scope is in the Authorization Request and the provider supports OpenID protocol.

#### Instances

Instances details

FromJSON OAuth2Token Source # | Parse JSON data into `OAuth2Token`
Instance details Defined in Network.OAuth.OAuth2.Internal Methods parseJSON :: Value -> Parser OAuth2Token Source # parseJSONList :: Value -> Parser [OAuth2Token] Source #
ToJSON OAuth2Token Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods toJSON :: OAuth2Token -> Value Source # toEncoding :: OAuth2Token -> Encoding Source # toJSONList :: [OAuth2Token] -> Value Source # toEncodingList :: [OAuth2Token] -> Encoding Source #
Generic OAuth2Token Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Associated Types type Rep OAuth2Token :: Type -> Type Source # Methods from :: OAuth2Token -> Rep OAuth2Token x Source # to :: Rep OAuth2Token x -> OAuth2Token Source #
Show OAuth2Token Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods showsPrec :: Int -> OAuth2Token -> ShowS Source # show :: OAuth2Token -> String Source # showList :: [OAuth2Token] -> ShowS Source #
Binary OAuth2Token Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods put :: OAuth2Token -> Put Source # get :: Get OAuth2Token Source # putList :: [OAuth2Token] -> Put Source #
Eq OAuth2Token Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods (==) :: OAuth2Token -> OAuth2Token -> Bool Source # (/=) :: OAuth2Token -> OAuth2Token -> Bool Source #
type Rep OAuth2Token Source # |

Instance details

Defined in Network.OAuth.OAuth2.Internal

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

# Client Authentication methods

data ClientAuthenticationMethod Source #

https://www.rfc-editor.org/rfc/rfc6749#section-2.3 According to spec:

The client MUST NOT use more than one authentication method in each request.

Which means use Authorization header or Post body.

However, I found I have to include authentication in the header all the time in real world.

In other words, `ClientSecretBasic` is always assured. `ClientSecretPost` is optional.

Maybe consider an alternative implementation that boolean kind of data type is good enough.

Constructors

ClientSecretBasic |
ClientSecretPost |
ClientAssertionJwt |

#### Instances

Instances details

Eq ClientAuthenticationMethod Source # |
Instance details Defined in Network.OAuth.OAuth2.Internal Methods (==) :: ClientAuthenticationMethod -> ClientAuthenticationMethod -> Bool Source # (/=) :: ClientAuthenticationMethod -> ClientAuthenticationMethod -> Bool Source #

# Utilies for Request and URI

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

Type synonym of post body content

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

Type sysnonym of request query params

defaultRequestHeaders :: [(HeaderName, ByteString)] Source #

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 #

# Authorization Requset

authorizationUrl :: OAuth2 -> URI Source #

See `authorizationUrlWithParams`

authorizationUrlWithParams :: QueryParams -> OAuth2 -> URI Source #

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

Since: 2.6.0

# Token Request

module Network.OAuth.OAuth2.TokenRequest

# OAuth'ed http client utilities

module Network.OAuth.OAuth2.HttpClient