hoauth2-2.8.0: Haskell OAuth2 authentication client

Safe Haskell | Safe-Inferred
Language | Haskell2010

Network.OAuth2.Experiment

Contents

- Grant Type
- Response Type value
- Grant Type value
- Scope
- Credentials
- Query parameters
- Authorization and Token Requests types
- User Info types
- Idp App
- Idp App Config
- Authorization Code flow
- JWTBearer
- Password flow
- Client Credentials flow

Description

This module contains a new way of doing OAuth2 authorization and authentication in order to obtain Access Token and maybe Refresh Token base on rfc6749.

This module will become default in future release. (TBD but likely 3.0).

The key concept/change is to introduce the `GrantTypeFlow`, which determines the entire work flow per spec. Each work flow will have slight different request parameters, which often time you'll see different configuration when creating OAuth2 application in the IdP developer application page.

Here are supported flows

1. Authorization Code. This flow requires authorize call to obtain an authorize code, then exchange the code for tokens.
2. Resource Owner Password. This flow only requires to hit token endpoint with, of course, username and password, to obtain tokens.
3. Client Credentials. This flow also only requires to hit token endpoint but with different parameters. Client credentials flow does not involve an end user hence you won't be able to hit userinfo endpoint with access token obtained.
4. PKCE (rfc7636). This is enhancement on top of authorization code flow.

Implicit flow is not supported because it is more for SPA (single page app) and more or less obsolete by Authorization Code flow with PKCE.

Here is quick sample for how to use vocabularies from this new module.

Firstly, initialize your IdP (use google as example) and the application.

    {-# LANGUAGE DataKinds #-}

    data Google = Google deriving (Eq, Show)
    googleIdp :: Idp Google
    googleIdp =
      Idp
        { idpFetchUserInfo = authGetJSON @(IdpUserInfo Google),
          idpAuthorizeEndpoint = [uri|https://accounts.google.com/o/oauth2/v2/auth|],
          idpTokenEndpoint = [uri|https://oauth2.googleapis.com/token|],
          idpUserInfoEndpoint = [uri|https://www.googleapis.com/oauth2/v2/userinfo|]
        }

    fooApp :: IdpApplication 'AuthorizationCode Google
    fooApp =
      AuthorizationCodeIdpApplication
        { idpAppClientId = "xxxxx",
          idpAppClientSecret = "xxxxx",
          idpAppScope =
            Set.fromList
              [ "https://www.googleapis.com/auth/userinfo.email",
                "https://www.googleapis.com/auth/userinfo.profile"
              ],
          idpAppAuthorizeState = "CHANGE_ME",
          idpAppAuthorizeExtraParams = Map.empty,
          idpAppRedirectUri = [uri|http://localhost/oauth2/callback|],
          idpAppName = "default-google-App",
          idpAppTokenRequestAuthenticationMethod = ClientSecretBasic,
          idp = googleIdp
        }

Secondly, construct the authorize URL.

    authorizeUrl = mkAuthorizeRequest fooApp

Thirdly, after a successful redirect with authorize code, you could exchange for access token

    mgr <- liftIO $ newManager tlsManagerSettings
    tokenResp <- conduitTokenRequest fooApp mgr authorizeCode

Lastly, you probably like to fetch user info

    conduitUserInfoRequest fooApp mgr (accessToken tokenResp)

Also you could find example from `hoauth2-providers-tutorials` module.

Synopsis

- data GrantTypeFlow
  - = AuthorizationCode
  - | ResourceOwnerPassword
  - | ClientCredentials
  - | JwtBearer
- class ToResponseTypeValue (a :: GrantTypeFlow) where
  - toResponseTypeValue :: IsString b => b
- toResponseTypeParam :: forall a b req. (ToResponseTypeValue a, IsString b) => req a -> Map b b
- newtype UrnOAuthParam a = UrnOAuthParam a
- data GrantTypeValue
  - = GTAuthorizationCode
  - | GTPassword
  - | GTClientCredentials
  - | GTRefreshToken
  - | GTJwtBearer
- newtype Scope = Scope {
  - unScope :: Text
  }
- newtype ClientId = ClientId {
  - unClientId :: Text
  }
- newtype ClientSecret = ClientSecret {
  - unClientSecret :: Text
  }
- toOAuth2Key :: ClientId -> ClientSecret -> OAuth2
- newtype RedirectUri = RedirectUri {
  - unRedirectUri :: URI
  }
- newtype AuthorizeState = AuthorizeState {
  - unAuthorizeState :: Text
  }
- newtype Username = Username {
  - unUsername :: Text
  }
- newtype Password = Password {
  - unPassword :: Text
  }
- class ToQueryParam a where
  - toQueryParam :: a -> Map Text Text
- class HasAuthorizeRequest (a :: GrantTypeFlow) where
  - data AuthorizationRequest a
  - type MkAuthorizationRequestResponse a
  - mkAuthorizeRequestParameter :: IdpApplication a i -> AuthorizationRequest a
  - mkAuthorizeRequest :: IdpApplication a i -> MkAuthorizationRequestResponse a
- class HasTokenRequest (a :: GrantTypeFlow) where
  - data TokenRequest a
  - type WithExchangeToken a b
  - mkTokenRequest :: IdpApplication a i -> WithExchangeToken a (TokenRequest a)
  - conduitTokenRequest :: MonadIO m => IdpApplication a i -> Manager -> WithExchangeToken a (ExceptT TokenRequestError m OAuth2Token)
- class HasPkceAuthorizeRequest (a :: GrantTypeFlow) where
  - mkPkceAuthorizeRequest :: MonadIO m => IdpApplication a i -> m (Text, CodeVerifier)
- class HasPkceTokenRequest (b :: GrantTypeFlow) where
  - conduitPkceTokenRequest :: MonadIO m => IdpApplication b i -> Manager -> (ExchangeToken, CodeVerifier) -> ExceptT TokenRequestError m OAuth2Token
- class HasRefreshTokenRequest (a :: GrantTypeFlow) where
  - data RefreshTokenRequest a
  - mkRefreshTokenRequest :: IdpApplication a i -> RefreshToken -> RefreshTokenRequest a
  - conduitRefreshTokenRequest :: MonadIO m => IdpApplication a i -> Manager -> RefreshToken -> ExceptT TokenRequestError m OAuth2Token
- type family IdpUserInfo a
- class HasUserInfoRequest (a :: GrantTypeFlow) where
  - conduitUserInfoRequest :: FromJSON (IdpUserInfo i) => IdpApplication a i -> Manager -> AccessToken -> ExceptT ByteString IO (IdpUserInfo i)
- data Idp a = Idp {
  - idpUserInfoEndpoint :: URI
  - idpAuthorizeEndpoint :: URI
  - idpTokenEndpoint :: URI
  - idpFetchUserInfo :: forall m. (FromJSON (IdpUserInfo a), MonadIO m) => Manager -> AccessToken -> URI -> ExceptT ByteString m (IdpUserInfo a)
  }
- data family IdpApplication (a :: GrantTypeFlow) (i :: Type)
- mkPkceParam :: MonadIO m => m PkceRequestParam
- newtype CodeChallenge = CodeChallenge {
  - unCodeChallenge :: Text
  }
- newtype CodeVerifier = CodeVerifier {
  - unCodeVerifier :: Text
  }
- data CodeChallengeMethod = S256
- data PkceRequestParam = PkceRequestParam {
  - codeVerifier :: CodeVerifier
  - codeChallenge :: CodeChallenge
  - codeChallengeMethod :: CodeChallengeMethod
  }

# Grant Type

data GrantTypeFlow Source #

Constructors

AuthorizationCode | https://www.rfc-editor.org/rfc/rfc6749#section-4.1
ResourceOwnerPassword | https://www.rfc-editor.org/rfc/rfc6749#section-4.3
ClientCredentials | https://www.rfc-editor.org/rfc/rfc6749#section-4.4
JwtBearer | https://www.rfc-editor.org/rfc/rfc7523.html#section-2.1

# Response Type value

class ToResponseTypeValue (a :: GrantTypeFlow) where Source #

Methods

toResponseTypeValue :: IsString b => b Source #

#### Instances

Instances details

ToResponseTypeValue 'AuthorizationCode Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toResponseTypeValue :: IsString b => b Source #

toResponseTypeParam :: forall a b req. (ToResponseTypeValue a, IsString b) => req a -> Map b b Source #

# Grant Type value

newtype UrnOAuthParam a Source #

Constructors

UrnOAuthParam a |

data GrantTypeValue Source #

Grant type query parameter has association with `GrantTypeFlow` but not completely strict.

e.g. Both `AuthorizationCode` and `ResourceOwnerPassword` flow could support refresh token flow.

Constructors

GTAuthorizationCode |
GTPassword |
GTClientCredentials |
GTRefreshToken |
GTJwtBearer |

#### Instances

Instances details

Show GrantTypeValue Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods showsPrec :: Int -> GrantTypeValue -> ShowS Source # show :: GrantTypeValue -> String Source # showList :: [GrantTypeValue] -> ShowS Source #
Eq GrantTypeValue Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods (==) :: GrantTypeValue -> GrantTypeValue -> Bool Source # (/=) :: GrantTypeValue -> GrantTypeValue -> Bool Source #
ToQueryParam GrantTypeValue Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: GrantTypeValue -> Map Text Text Source #

# Scope

newtype Scope Source #

Constructors

Scope |

Fields

- unScope :: Text

#### Instances

Instances details

IsString Scope Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods fromString :: String -> Scope Source #
Show Scope Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods showsPrec :: Int -> Scope -> ShowS Source # show :: Scope -> String Source # showList :: [Scope] -> ShowS Source #
Eq Scope Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods (==) :: Scope -> Scope -> Bool Source # (/=) :: Scope -> Scope -> Bool Source #
Ord Scope Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods compare :: Scope -> Scope -> Ordering Source # (<) :: Scope -> Scope -> Bool Source # (<=) :: Scope -> Scope -> Bool Source # (>) :: Scope -> Scope -> Bool Source # (>=) :: Scope -> Scope -> Bool Source # max :: Scope -> Scope -> Scope Source # min :: Scope -> Scope -> Scope Source #
ToQueryParam (Set Scope) Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: Set Scope -> Map Text Text Source #

# Credentials

newtype ClientId Source #

Constructors

ClientId |

Fields

- unClientId :: Text

#### Instances

Instances details

IsString ClientId Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods fromString :: String -> ClientId Source #
Show ClientId Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods showsPrec :: Int -> ClientId -> ShowS Source # show :: ClientId -> String Source # showList :: [ClientId] -> ShowS Source #
Eq ClientId Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods (==) :: ClientId -> ClientId -> Bool Source # (/=) :: ClientId -> ClientId -> Bool Source #
ToQueryParam ClientId Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: ClientId -> Map Text Text Source #

newtype ClientSecret Source #

Can be either "Client Secret" or JWT base on client authentication method

Constructors

ClientSecret |

Fields

- unClientSecret :: Text

#### Instances

Instances details

IsString ClientSecret Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods fromString :: String -> ClientSecret Source #
Eq ClientSecret Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods (==) :: ClientSecret -> ClientSecret -> Bool Source # (/=) :: ClientSecret -> ClientSecret -> Bool Source #
ToQueryParam ClientSecret Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: ClientSecret -> Map Text Text Source #

toOAuth2Key :: ClientId -> ClientSecret -> OAuth2 Source #

In order to reuse some methods from legacy Network.OAuth.OAuth2. Will be removed when Experiment module becomes default.

newtype RedirectUri Source #

Constructors

RedirectUri |

Fields

- unRedirectUri :: URI

#### Instances

Instances details

Eq RedirectUri Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods (==) :: RedirectUri -> RedirectUri -> Bool Source # (/=) :: RedirectUri -> RedirectUri -> Bool Source #
ToQueryParam RedirectUri Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: RedirectUri -> Map Text Text Source #

newtype AuthorizeState Source #

Constructors

AuthorizeState |

Fields

- unAuthorizeState :: Text

#### Instances

Instances details

IsString AuthorizeState Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods fromString :: String -> AuthorizeState Source #
Eq AuthorizeState Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods (==) :: AuthorizeState -> AuthorizeState -> Bool Source # (/=) :: AuthorizeState -> AuthorizeState -> Bool Source #
ToQueryParam AuthorizeState Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: AuthorizeState -> Map Text Text Source #

newtype Username Source #

Constructors

Username |

Fields

- unUsername :: Text

#### Instances

Instances details

IsString Username Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods fromString :: String -> Username Source #
Eq Username Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods (==) :: Username -> Username -> Bool Source # (/=) :: Username -> Username -> Bool Source #
ToQueryParam Username Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: Username -> Map Text Text Source #

newtype Password Source #

Constructors

Password |

Fields

- unPassword :: Text

#### Instances

Instances details

IsString Password Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods fromString :: String -> Password Source #
Eq Password Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods (==) :: Password -> Password -> Bool Source # (/=) :: Password -> Password -> Bool Source #
ToQueryParam Password Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: Password -> Map Text Text Source #

# Query parameters

class ToQueryParam a where Source #

Methods

toQueryParam :: a -> Map Text Text Source #

#### Instances

Instances details

ToQueryParam ExchangeToken Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: ExchangeToken -> Map Text Text Source #
ToQueryParam RefreshToken Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: RefreshToken -> Map Text Text Source #
ToQueryParam CodeChallenge Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: CodeChallenge -> Map Text Text Source #
ToQueryParam CodeChallengeMethod Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: CodeChallengeMethod -> Map Text Text Source #
ToQueryParam CodeVerifier Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: CodeVerifier -> Map Text Text Source #
ToQueryParam AuthorizeState Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: AuthorizeState -> Map Text Text Source #
ToQueryParam ClientId Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: ClientId -> Map Text Text Source #
ToQueryParam ClientSecret Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: ClientSecret -> Map Text Text Source #
ToQueryParam GrantTypeValue Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: GrantTypeValue -> Map Text Text Source #
ToQueryParam Password Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: Password -> Map Text Text Source #
ToQueryParam RedirectUri Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: RedirectUri -> Map Text Text Source #
ToQueryParam Username Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: Username -> Map Text Text Source #
ToQueryParam (Set Scope) Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: Set Scope -> Map Text Text Source #
ToQueryParam (AuthorizationRequest 'AuthorizationCode) Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: AuthorizationRequest 'AuthorizationCode -> Map Text Text Source #
ToQueryParam (RefreshTokenRequest 'AuthorizationCode) Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: RefreshTokenRequest 'AuthorizationCode -> Map Text Text Source #
ToQueryParam (TokenRequest 'AuthorizationCode) Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: TokenRequest 'AuthorizationCode -> Map Text Text Source #
ToQueryParam (TokenRequest 'ClientCredentials) Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: TokenRequest 'ClientCredentials -> Map Text Text Source #
ToQueryParam (TokenRequest 'JwtBearer) Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: TokenRequest 'JwtBearer -> Map Text Text Source #
ToQueryParam (TokenRequest 'ResourceOwnerPassword) Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: TokenRequest 'ResourceOwnerPassword -> Map Text Text Source #
ToQueryParam a => ToQueryParam (Maybe a) Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: Maybe a -> Map Text Text Source #

# Authorization and Token Requests types

class HasAuthorizeRequest (a :: GrantTypeFlow) where Source #

Associated Types

data AuthorizationRequest a Source #

type MkAuthorizationRequestResponse a Source #

Methods

mkAuthorizeRequestParameter :: IdpApplication a i -> AuthorizationRequest a Source #

mkAuthorizeRequest :: IdpApplication a i -> MkAuthorizationRequestResponse a Source #

#### Instances

Instances details

HasAuthorizeRequest 'AuthorizationCode Source # |

Instance details

Defined in Network.OAuth2.Experiment.Types

Associated Types

data AuthorizationRequest 'AuthorizationCode Source #

type MkAuthorizationRequestResponse 'AuthorizationCode Source #

Methods

mkAuthorizeRequestParameter :: IdpApplication 'AuthorizationCode i -> AuthorizationRequest 'AuthorizationCode Source #

mkAuthorizeRequest :: IdpApplication 'AuthorizationCode i -> MkAuthorizationRequestResponse 'AuthorizationCode Source #

class HasTokenRequest (a :: GrantTypeFlow) where Source #

Associated Types

data TokenRequest a Source #

Each GrantTypeFlow has slightly different request parameter to /token endpoint.

type WithExchangeToken a b Source #

Only 'AuthorizationCode flow (but not resource owner password nor client credentials) will use `ExchangeToken` in the token request create type family to be explicit on it. with 'type instance WithExchangeToken a b = b' implies no exchange token v.s. 'type instance WithExchangeToken a b = ExchangeToken -> b' implies needing an exchange token

Methods

mkTokenRequest :: IdpApplication a i -> WithExchangeToken a (TokenRequest a) Source #

conduitTokenRequest :: MonadIO m => IdpApplication a i -> Manager -> WithExchangeToken a (ExceptT TokenRequestError m OAuth2Token) Source #

#### Instances

Instances details

HasTokenRequest 'AuthorizationCode Source # |

Instance details

Defined in Network.OAuth2.Experiment.Types

Associated Types

data TokenRequest 'AuthorizationCode Source #

type WithExchangeToken 'AuthorizationCode b Source #

Methods

mkTokenRequest :: IdpApplication 'AuthorizationCode i -> WithExchangeToken 'AuthorizationCode (TokenRequest 'AuthorizationCode) Source #

conduitTokenRequest :: forall (m :: Type -> Type) i. MonadIO m => IdpApplication 'AuthorizationCode i -> Manager -> WithExchangeToken 'AuthorizationCode (ExceptT TokenRequestError m OAuth2Token) Source #

HasTokenRequest 'ClientCredentials Source # |

Instance details

Defined in Network.OAuth2.Experiment.Types

Associated Types

data TokenRequest 'ClientCredentials Source #

type WithExchangeToken 'ClientCredentials b Source #

Methods

mkTokenRequest :: IdpApplication 'ClientCredentials i -> WithExchangeToken 'ClientCredentials (TokenRequest 'ClientCredentials) Source #

conduitTokenRequest :: forall (m :: Type -> Type) i. MonadIO m => IdpApplication 'ClientCredentials i -> Manager -> WithExchangeToken 'ClientCredentials (ExceptT TokenRequestError m OAuth2Token) Source #

HasTokenRequest 'JwtBearer Source # |

Instance details

Defined in Network.OAuth2.Experiment.Types

Associated Types

data TokenRequest 'JwtBearer Source #

type WithExchangeToken 'JwtBearer b Source #

Methods

mkTokenRequest :: IdpApplication 'JwtBearer i -> WithExchangeToken 'JwtBearer (TokenRequest 'JwtBearer) Source #

conduitTokenRequest :: forall (m :: Type -> Type) i. MonadIO m => IdpApplication 'JwtBearer i -> Manager -> WithExchangeToken 'JwtBearer (ExceptT TokenRequestError m OAuth2Token) Source #

HasTokenRequest 'ResourceOwnerPassword Source # |

Instance details

Defined in Network.OAuth2.Experiment.Types

Associated Types

data TokenRequest 'ResourceOwnerPassword Source #

type WithExchangeToken 'ResourceOwnerPassword b Source #

Methods

mkTokenRequest :: IdpApplication 'ResourceOwnerPassword i -> WithExchangeToken 'ResourceOwnerPassword (TokenRequest 'ResourceOwnerPassword) Source #

conduitTokenRequest :: forall (m :: Type -> Type) i. MonadIO m => IdpApplication 'ResourceOwnerPassword i -> Manager -> WithExchangeToken 'ResourceOwnerPassword (ExceptT TokenRequestError m OAuth2Token) Source #

class HasPkceAuthorizeRequest (a :: GrantTypeFlow) where Source #

Methods

mkPkceAuthorizeRequest :: MonadIO m => IdpApplication a i -> m (Text, CodeVerifier) Source #

#### Instances

Instances details

HasPkceAuthorizeRequest 'AuthorizationCode Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods mkPkceAuthorizeRequest :: MonadIO m => IdpApplication 'AuthorizationCode i -> m (Text, CodeVerifier) Source #

class HasPkceTokenRequest (b :: GrantTypeFlow) where Source #

Methods

conduitPkceTokenRequest :: MonadIO m => IdpApplication b i -> Manager -> (ExchangeToken, CodeVerifier) -> ExceptT TokenRequestError m OAuth2Token Source #

#### Instances

Instances details

HasPkceTokenRequest 'AuthorizationCode Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods conduitPkceTokenRequest :: forall (m :: Type -> Type) i. MonadIO m => IdpApplication 'AuthorizationCode i -> Manager -> (ExchangeToken, CodeVerifier) -> ExceptT TokenRequestError m OAuth2Token Source #

class HasRefreshTokenRequest (a :: GrantTypeFlow) where Source #

Associated Types

data RefreshTokenRequest a Source #

https://www.rfc-editor.org/rfc/rfc6749#page-47

Methods

mkRefreshTokenRequest :: IdpApplication a i -> RefreshToken -> RefreshTokenRequest a Source #

conduitRefreshTokenRequest :: MonadIO m => IdpApplication a i -> Manager -> RefreshToken -> ExceptT TokenRequestError m OAuth2Token Source #

#### Instances

Instances details

HasRefreshTokenRequest 'AuthorizationCode Source # |

Instance details

Defined in Network.OAuth2.Experiment.Types

Associated Types

data RefreshTokenRequest 'AuthorizationCode Source #

Methods

mkRefreshTokenRequest :: IdpApplication 'AuthorizationCode i -> RefreshToken -> RefreshTokenRequest 'AuthorizationCode Source #

conduitRefreshTokenRequest :: forall (m :: Type -> Type) i. MonadIO m => IdpApplication 'AuthorizationCode i -> Manager -> RefreshToken -> ExceptT TokenRequestError m OAuth2Token Source #

HasRefreshTokenRequest 'ResourceOwnerPassword Source # | TODO: TBD

Instance details

Defined in Network.OAuth2.Experiment.Types

Associated Types

data RefreshTokenRequest 'ResourceOwnerPassword Source #

Methods

mkRefreshTokenRequest :: IdpApplication 'ResourceOwnerPassword i -> RefreshToken -> RefreshTokenRequest 'ResourceOwnerPassword Source #

conduitRefreshTokenRequest :: forall (m :: Type -> Type) i. MonadIO m => IdpApplication 'ResourceOwnerPassword i -> Manager -> RefreshToken -> ExceptT TokenRequestError m OAuth2Token Source #

# User Info types

type family IdpUserInfo a Source #

class HasUserInfoRequest (a :: GrantTypeFlow) where Source #

Methods

conduitUserInfoRequest :: FromJSON (IdpUserInfo i) => IdpApplication a i -> Manager -> AccessToken -> ExceptT ByteString IO (IdpUserInfo i) Source #

#### Instances

Instances details

HasUserInfoRequest 'AuthorizationCode Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods conduitUserInfoRequest :: FromJSON (IdpUserInfo i) => IdpApplication 'AuthorizationCode i -> Manager -> AccessToken -> ExceptT ByteString IO (IdpUserInfo i) Source #
HasUserInfoRequest 'JwtBearer Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods conduitUserInfoRequest :: FromJSON (IdpUserInfo i) => IdpApplication 'JwtBearer i -> Manager -> AccessToken -> ExceptT ByteString IO (IdpUserInfo i) Source #
HasUserInfoRequest 'ResourceOwnerPassword Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods conduitUserInfoRequest :: FromJSON (IdpUserInfo i) => IdpApplication 'ResourceOwnerPassword i -> Manager -> AccessToken -> ExceptT ByteString IO (IdpUserInfo i) Source #

# Idp App

data Idp a Source #

Shall IdpApplication has a field of 'Idp a'??

Constructors

Idp |

Fields

- idpUserInfoEndpoint :: URI
- idpAuthorizeEndpoint :: URI
- idpTokenEndpoint :: URI
- idpFetchUserInfo :: forall m. (FromJSON (IdpUserInfo a), MonadIO m) => Manager -> AccessToken -> URI -> ExceptT ByteString m (IdpUserInfo a)

# Idp App Config

data family IdpApplication (a :: GrantTypeFlow) (i :: Type) Source #

#### Instances

Instances details

data IdpApplication 'AuthorizationCode i Source # | An Application that supports "Authorization code" flow

Instance details

Defined in Network.OAuth2.Experiment.Types

data IdpApplication 'AuthorizationCode i = AuthorizationCodeIdpApplication {

- idpAppName :: Text
- idpAppClientId :: ClientId
- idpAppClientSecret :: ClientSecret
- idpAppScope :: Set Scope
- idpAppRedirectUri :: URI
- idpAppAuthorizeState :: AuthorizeState
- idpAppAuthorizeExtraParams :: Map Text Text
- idpAppTokenRequestAuthenticationMethod :: ClientAuthenticationMethod
- idp :: Idp i

}

data IdpApplication 'ClientCredentials i Source # |

Instance details

Defined in Network.OAuth2.Experiment.Types

data IdpApplication 'ClientCredentials i = ClientCredentialsIDPApplication {

- idpAppClientId :: ClientId
- idpAppClientSecret :: ClientSecret
- idpAppTokenRequestAuthenticationMethod :: ClientAuthenticationMethod
- idpAppName :: Text
- idpAppScope :: Set Scope
- idpAppTokenRequestExtraParams :: Map Text Text
- idp :: Idp i

}

data IdpApplication 'JwtBearer i Source # | An Application that supports "Authorization code" flow

Instance details

Defined in Network.OAuth2.Experiment.Types

data IdpApplication 'JwtBearer i = JwtBearerIdpApplication {

- idpAppName :: Text
- idpAppJwt :: ByteString
- idp :: Idp i

}

data IdpApplication 'ResourceOwnerPassword i Source # |

Instance details

Defined in Network.OAuth2.Experiment.Types

data IdpApplication 'ResourceOwnerPassword i = ResourceOwnerPasswordIDPApplication {

- idpAppClientId :: ClientId
- idpAppClientSecret :: ClientSecret
- idpAppName :: Text
- idpAppScope :: Set Scope
- idpAppUserName :: Username
- idpAppPassword :: Password
- idpAppTokenRequestExtraParams :: Map Text Text
- idp :: Idp i

}

# Authorization Code flow

# JWTBearer

# Password flow

# Client Credentials flow

mkPkceParam :: MonadIO m => m PkceRequestParam Source #

newtype CodeChallenge Source #

Constructors

CodeChallenge |

Fields

- unCodeChallenge :: Text

#### Instances

Instances details

ToQueryParam CodeChallenge Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: CodeChallenge -> Map Text Text Source #

newtype CodeVerifier Source #

Constructors

CodeVerifier |

Fields

- unCodeVerifier :: Text

#### Instances

Instances details

Show CodeVerifier Source # |
Instance details Defined in Network.OAuth2.Experiment.Pkce Methods showsPrec :: Int -> CodeVerifier -> ShowS Source # show :: CodeVerifier -> String Source # showList :: [CodeVerifier] -> ShowS Source #
ToQueryParam CodeVerifier Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: CodeVerifier -> Map Text Text Source #

data CodeChallengeMethod Source #

Constructors

S256 |

#### Instances

Instances details

Show CodeChallengeMethod Source # |
Instance details Defined in Network.OAuth2.Experiment.Pkce Methods showsPrec :: Int -> CodeChallengeMethod -> ShowS Source # show :: CodeChallengeMethod -> String Source # showList :: [CodeChallengeMethod] -> ShowS Source #
ToQueryParam CodeChallengeMethod Source # |
Instance details Defined in Network.OAuth2.Experiment.Types Methods toQueryParam :: CodeChallengeMethod -> Map Text Text Source #

data PkceRequestParam Source #

Constructors

PkceRequestParam |

Fields

- codeVerifier :: CodeVerifier
- codeChallenge :: CodeChallenge
- codeChallengeMethod :: CodeChallengeMethod

  spec says optional but really it shall be s256 or can be omitted? https://datatracker.ietf.org/doc/html/rfc7636#section-4.3