{-|

Copyright:

  This file is part of the package openid-connect.  It is subject to
  the license terms in the LICENSE file found in the top-level
  directory of this distribution and at:

    https://code.devalot.com/open/openid-connect

  No part of this package, including this file, may be copied,
  modified, propagated, or distributed except according to the terms
  contained in the LICENSE file.

License: BSD-2-Clause

-}
module OpenID.Connect.TokenResponse
  (
    -- * Token Response
    TokenResponse(..)

    -- * Re-exports
  , Words(..)
  , toWords
  , fromWords
  ) where

--------------------------------------------------------------------------------
-- Imports:
import Data.Text (Text)
import GHC.Generics (Generic)
import OpenID.Connect.JSON

--------------------------------------------------------------------------------
-- | Authentication access token response.
--
-- RFC 6749 section 5.1. with an additional field specified in OpenID
-- Connect Core 1.0 section 3.1.3.3.
data TokenResponse a = TokenResponse
  { forall a. TokenResponse a -> Text
accessToken :: Text
    -- ^ The access token issued by the authorization server.

  , forall a. TokenResponse a -> Text
tokenType :: Text
    -- ^ The type of the token issued as described in Section 7.1.
    -- Value is case insensitive.

  , forall a. TokenResponse a -> Maybe Int
expiresIn :: Maybe Int
    -- ^ The lifetime in seconds of the access token.

  , forall a. TokenResponse a -> Maybe Text
refreshToken :: Maybe Text
    -- ^ The refresh token, which can be used to obtain new access
    -- tokens using the same authorization grant as described in
    -- Section 6.

  , forall a. TokenResponse a -> Maybe Words
scope :: Maybe Words
    -- ^ The scope of the access token as described by Section 3.3.

  , forall a. TokenResponse a -> a
idToken :: a
    -- ^ ID Token value associated with the authenticated session.

  , forall a. TokenResponse a -> Maybe Text
atHash :: Maybe Text
    -- ^ Some flows include this hash.  Access Token hash value. Its
    -- value is the base64url encoding of the left-most half of the
    -- hash of the octets of the ASCII representation of the
    -- access_token value, where the hash algorithm used is the hash
    -- algorithm used in the alg Header Parameter of the ID Token's
    -- JOSE Header.
  }
  deriving stock (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (TokenResponse a) x -> TokenResponse a
forall a x. TokenResponse a -> Rep (TokenResponse a) x
$cto :: forall a x. Rep (TokenResponse a) x -> TokenResponse a
$cfrom :: forall a x. TokenResponse a -> Rep (TokenResponse a) x
Generic, forall a b. a -> TokenResponse b -> TokenResponse a
forall a b. (a -> b) -> TokenResponse a -> TokenResponse b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> TokenResponse b -> TokenResponse a
$c<$ :: forall a b. a -> TokenResponse b -> TokenResponse a
fmap :: forall a b. (a -> b) -> TokenResponse a -> TokenResponse b
$cfmap :: forall a b. (a -> b) -> TokenResponse a -> TokenResponse b
Functor)

deriving via (GenericJSON (TokenResponse Text)) instance ToJSON   (TokenResponse Text)
deriving via (GenericJSON (TokenResponse Text)) instance FromJSON (TokenResponse Text)
deriving via (GenericJSON (TokenResponse (Maybe Text))) instance ToJSON   (TokenResponse (Maybe Text))
deriving via (GenericJSON (TokenResponse (Maybe Text))) instance FromJSON (TokenResponse (Maybe Text))