{-# LANGUAGE OverloadedStrings #-}
module Web.OIDC.Client.Settings
(
OIDC(..)
, def
, newOIDC
, setCredentials
) where
import Data.ByteString (ByteString)
import Data.Text (Text)
import Web.OIDC.Client.Discovery.Provider (Provider)
import qualified Web.OIDC.Client.Discovery.Provider as P
data OIDC = OIDC
{ oidcAuthorizationServerUrl :: Text
, oidcTokenEndpoint :: Text
, oidcClientId :: ByteString
, oidcClientSecret :: ByteString
, oidcRedirectUri :: ByteString
, oidcProvider :: Provider
}
def :: OIDC
def = OIDC
{ oidcAuthorizationServerUrl = error "You must specify authorizationServerUrl"
, oidcTokenEndpoint = error "You must specify tokenEndpoint"
, oidcClientId = error "You must specify clientId"
, oidcClientSecret = error "You must specify clientSecret"
, oidcRedirectUri = error "You must specify redirectUri"
, oidcProvider = error "You must specify provider"
}
newOIDC
:: Provider
-> OIDC
newOIDC p =
def { oidcAuthorizationServerUrl = P.authorizationEndpoint . P.configuration $ p
, oidcTokenEndpoint = P.tokenEndpoint . P.configuration $ p
, oidcProvider = p
}
setCredentials
:: ByteString
-> ByteString
-> ByteString
-> OIDC
-> OIDC
setCredentials cid secret redirect oidc =
oidc { oidcClientId = cid
, oidcClientSecret = secret
, oidcRedirectUri = redirect
}