{-# 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
{ OIDC -> Text
oidcAuthorizationServerUrl :: Text
, OIDC -> Text
oidcTokenEndpoint :: Text
, OIDC -> ByteString
oidcClientId :: ByteString
, OIDC -> ByteString
oidcClientSecret :: ByteString
, OIDC -> ByteString
oidcRedirectUri :: ByteString
, OIDC -> Provider
oidcProvider :: Provider
}
def :: OIDC
def :: OIDC
def = OIDC
{ oidcAuthorizationServerUrl :: Text
oidcAuthorizationServerUrl = [Char] -> Text
forall a. HasCallStack => [Char] -> a
error [Char]
"You must specify authorizationServerUrl"
, oidcTokenEndpoint :: Text
oidcTokenEndpoint = [Char] -> Text
forall a. HasCallStack => [Char] -> a
error [Char]
"You must specify tokenEndpoint"
, oidcClientId :: ByteString
oidcClientId = [Char] -> ByteString
forall a. HasCallStack => [Char] -> a
error [Char]
"You must specify clientId"
, oidcClientSecret :: ByteString
oidcClientSecret = [Char] -> ByteString
forall a. HasCallStack => [Char] -> a
error [Char]
"You must specify clientSecret"
, oidcRedirectUri :: ByteString
oidcRedirectUri = [Char] -> ByteString
forall a. HasCallStack => [Char] -> a
error [Char]
"You must specify redirectUri"
, oidcProvider :: Provider
oidcProvider = [Char] -> Provider
forall a. HasCallStack => [Char] -> a
error [Char]
"You must specify provider"
}
newOIDC
:: Provider
-> OIDC
newOIDC :: Provider -> OIDC
newOIDC Provider
p =
OIDC
def { oidcAuthorizationServerUrl = P.authorizationEndpoint . P.configuration $ p
, oidcTokenEndpoint = P.tokenEndpoint . P.configuration $ p
, oidcProvider = p
}
setCredentials
:: ByteString
-> ByteString
-> ByteString
-> OIDC
-> OIDC
setCredentials :: ByteString -> ByteString -> ByteString -> OIDC -> OIDC
setCredentials ByteString
cid ByteString
secret ByteString
redirect OIDC
oidc =
OIDC
oidc { oidcClientId = cid
, oidcClientSecret = secret
, oidcRedirectUri = redirect
}