module OpenID.Connect.Authentication
( ClientAuthentication(..)
, ClientSecret(..)
, Credentials(..)
, ClientID
, ClientRedirectURI
, AuthenticationRequest(..)
) where
import Control.Applicative ((<|>))
import Crypto.JOSE.JWK (JWK)
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Types as Aeson
import Data.ByteString (ByteString)
import Data.Text (Text)
import GHC.Generics (Generic)
import Network.HTTP.Types (QueryItem)
import qualified Network.URI as Network
import OpenID.Connect.JSON (FromJSON, ToJSON, aesonOptions)
import OpenID.Connect.Scope
data ClientSecret
= AssignedSecretText Text
| AssignedAssertionText Text
| AssertionPrivateKey JWK
type ClientID = Text
type ClientRedirectURI = Network.URI
data Credentials = Credentials
{ Credentials -> ClientID
assignedClientId :: ClientID
, Credentials -> ClientSecret
clientSecret :: ClientSecret
, Credentials -> ClientRedirectURI
clientRedirectUri :: ClientRedirectURI
}
data AuthenticationRequest = AuthenticationRequest
{ AuthenticationRequest -> ClientRedirectURI
authRequestRedirectURI :: ClientRedirectURI
, AuthenticationRequest -> ClientID
authRequestClientId :: Text
, AuthenticationRequest -> Scope
authRequestScope :: Scope
, AuthenticationRequest -> ByteString
authRequestResponseType :: ByteString
, AuthenticationRequest -> Maybe ByteString
authRequestDisplay :: Maybe ByteString
, AuthenticationRequest -> Maybe ByteString
authRequestPrompt :: Maybe ByteString
, AuthenticationRequest -> Maybe Int
authRequestMaxAge :: Maybe Int
, AuthenticationRequest -> Maybe Words
authRequestUiLocales :: Maybe Words
, AuthenticationRequest -> Maybe ByteString
authRequestIdTokenHint :: Maybe ByteString
, AuthenticationRequest -> Maybe ClientID
authRequestLoginHint :: Maybe Text
, AuthenticationRequest -> Maybe Words
authRequestAcrValues :: Maybe Words
, AuthenticationRequest -> [QueryItem]
authRequestOtherParams :: [QueryItem]
}
data ClientAuthentication
= ClientSecretBasic
| ClientSecretPost
| ClientSecretJwt
| PrivateKeyJwt
| None
| UnsupportedAuthentication Text
deriving stock (forall x. Rep ClientAuthentication x -> ClientAuthentication
forall x. ClientAuthentication -> Rep ClientAuthentication x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ClientAuthentication x -> ClientAuthentication
$cfrom :: forall x. ClientAuthentication -> Rep ClientAuthentication x
Generic, ClientAuthentication -> ClientAuthentication -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClientAuthentication -> ClientAuthentication -> Bool
$c/= :: ClientAuthentication -> ClientAuthentication -> Bool
== :: ClientAuthentication -> ClientAuthentication -> Bool
$c== :: ClientAuthentication -> ClientAuthentication -> Bool
Eq, Int -> ClientAuthentication -> ShowS
[ClientAuthentication] -> ShowS
ClientAuthentication -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClientAuthentication] -> ShowS
$cshowList :: [ClientAuthentication] -> ShowS
show :: ClientAuthentication -> String
$cshow :: ClientAuthentication -> String
showsPrec :: Int -> ClientAuthentication -> ShowS
$cshowsPrec :: Int -> ClientAuthentication -> ShowS
Show)
clientAuthAesonOptions :: Aeson.Options
clientAuthAesonOptions :: Options
clientAuthAesonOptions = Options
aesonOptions{ sumEncoding :: SumEncoding
Aeson.sumEncoding = SumEncoding
Aeson.UntaggedValue }
instance ToJSON ClientAuthentication where
toJSON :: ClientAuthentication -> Value
toJSON (UnsupportedAuthentication ClientID
txt) = ClientID -> Value
Aeson.String ClientID
txt
toJSON ClientAuthentication
a = forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
Aeson.genericToJSON Options
clientAuthAesonOptions ClientAuthentication
a
instance FromJSON ClientAuthentication where
parseJSON :: Value -> Parser ClientAuthentication
parseJSON v :: Value
v@(Aeson.String ClientID
txt) =
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
Aeson.genericParseJSON Options
clientAuthAesonOptions Value
v
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClientID -> ClientAuthentication
UnsupportedAuthentication ClientID
txt)
parseJSON Value
v =
forall a. String -> Parser a -> Parser a
Aeson.prependFailure String
"parsing ClientAuthentication failed, " (forall a. String -> Value -> Parser a
Aeson.typeMismatch String
"String" Value
v)