{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SSOOIDC.CreateToken
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates and returns an access token for the authorized client. The
-- access token issued will be used to fetch short-term credentials for the
-- assigned roles in the AWS account.
module Amazonka.SSOOIDC.CreateToken
  ( -- * Creating a Request
    CreateToken (..),
    newCreateToken,

    -- * Request Lenses
    createToken_redirectUri,
    createToken_refreshToken,
    createToken_scope,
    createToken_code,
    createToken_clientId,
    createToken_clientSecret,
    createToken_grantType,
    createToken_deviceCode,

    -- * Destructuring the Response
    CreateTokenResponse (..),
    newCreateTokenResponse,

    -- * Response Lenses
    createTokenResponse_accessToken,
    createTokenResponse_refreshToken,
    createTokenResponse_expiresIn,
    createTokenResponse_tokenType,
    createTokenResponse_idToken,
    createTokenResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SSOOIDC.Types

-- | /See:/ 'newCreateToken' smart constructor.
data CreateToken = CreateToken'
  { -- | The location of the application that will receive the authorization
    -- code. Users authorize the service to send the request to this location.
    CreateToken -> Maybe Text
redirectUri :: Prelude.Maybe Prelude.Text,
    -- | The token used to obtain an access token in the event that the access
    -- token is invalid or expired. This token is not issued by the service.
    CreateToken -> Maybe Text
refreshToken :: Prelude.Maybe Prelude.Text,
    -- | The list of scopes that is defined by the client. Upon authorization,
    -- this list is used to restrict permissions when granting an access token.
    CreateToken -> Maybe [Text]
scope :: Prelude.Maybe [Prelude.Text],
    -- | The authorization code received from the authorization service. This
    -- parameter is required to perform an authorization grant request to get
    -- access to a token.
    CreateToken -> Maybe Text
code :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier string for each client. This value should come
    -- from the persisted result of the RegisterClient API.
    CreateToken -> Text
clientId :: Prelude.Text,
    -- | A secret string generated for the client. This value should come from
    -- the persisted result of the RegisterClient API.
    CreateToken -> Text
clientSecret :: Prelude.Text,
    -- | Supports grant types for authorization code, refresh token, and device
    -- code request.
    CreateToken -> Text
grantType :: Prelude.Text,
    -- | Used only when calling this API for the device code grant type. This
    -- short-term code is used to identify this authentication attempt. This
    -- should come from an in-memory reference to the result of the
    -- StartDeviceAuthorization API.
    CreateToken -> Text
deviceCode :: Prelude.Text
  }
  deriving (CreateToken -> CreateToken -> Bool
(CreateToken -> CreateToken -> Bool)
-> (CreateToken -> CreateToken -> Bool) -> Eq CreateToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateToken -> CreateToken -> Bool
$c/= :: CreateToken -> CreateToken -> Bool
== :: CreateToken -> CreateToken -> Bool
$c== :: CreateToken -> CreateToken -> Bool
Prelude.Eq, ReadPrec [CreateToken]
ReadPrec CreateToken
Int -> ReadS CreateToken
ReadS [CreateToken]
(Int -> ReadS CreateToken)
-> ReadS [CreateToken]
-> ReadPrec CreateToken
-> ReadPrec [CreateToken]
-> Read CreateToken
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateToken]
$creadListPrec :: ReadPrec [CreateToken]
readPrec :: ReadPrec CreateToken
$creadPrec :: ReadPrec CreateToken
readList :: ReadS [CreateToken]
$creadList :: ReadS [CreateToken]
readsPrec :: Int -> ReadS CreateToken
$creadsPrec :: Int -> ReadS CreateToken
Prelude.Read, Int -> CreateToken -> ShowS
[CreateToken] -> ShowS
CreateToken -> String
(Int -> CreateToken -> ShowS)
-> (CreateToken -> String)
-> ([CreateToken] -> ShowS)
-> Show CreateToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateToken] -> ShowS
$cshowList :: [CreateToken] -> ShowS
show :: CreateToken -> String
$cshow :: CreateToken -> String
showsPrec :: Int -> CreateToken -> ShowS
$cshowsPrec :: Int -> CreateToken -> ShowS
Prelude.Show, (forall x. CreateToken -> Rep CreateToken x)
-> (forall x. Rep CreateToken x -> CreateToken)
-> Generic CreateToken
forall x. Rep CreateToken x -> CreateToken
forall x. CreateToken -> Rep CreateToken x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateToken x -> CreateToken
$cfrom :: forall x. CreateToken -> Rep CreateToken x
Prelude.Generic)

-- |
-- Create a value of 'CreateToken' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'redirectUri', 'createToken_redirectUri' - The location of the application that will receive the authorization
-- code. Users authorize the service to send the request to this location.
--
-- 'refreshToken', 'createToken_refreshToken' - The token used to obtain an access token in the event that the access
-- token is invalid or expired. This token is not issued by the service.
--
-- 'scope', 'createToken_scope' - The list of scopes that is defined by the client. Upon authorization,
-- this list is used to restrict permissions when granting an access token.
--
-- 'code', 'createToken_code' - The authorization code received from the authorization service. This
-- parameter is required to perform an authorization grant request to get
-- access to a token.
--
-- 'clientId', 'createToken_clientId' - The unique identifier string for each client. This value should come
-- from the persisted result of the RegisterClient API.
--
-- 'clientSecret', 'createToken_clientSecret' - A secret string generated for the client. This value should come from
-- the persisted result of the RegisterClient API.
--
-- 'grantType', 'createToken_grantType' - Supports grant types for authorization code, refresh token, and device
-- code request.
--
-- 'deviceCode', 'createToken_deviceCode' - Used only when calling this API for the device code grant type. This
-- short-term code is used to identify this authentication attempt. This
-- should come from an in-memory reference to the result of the
-- StartDeviceAuthorization API.
newCreateToken ::
  -- | 'clientId'
  Prelude.Text ->
  -- | 'clientSecret'
  Prelude.Text ->
  -- | 'grantType'
  Prelude.Text ->
  -- | 'deviceCode'
  Prelude.Text ->
  CreateToken
newCreateToken :: Text -> Text -> Text -> Text -> CreateToken
newCreateToken
  Text
pClientId_
  Text
pClientSecret_
  Text
pGrantType_
  Text
pDeviceCode_ =
    CreateToken' :: Maybe Text
-> Maybe Text
-> Maybe [Text]
-> Maybe Text
-> Text
-> Text
-> Text
-> Text
-> CreateToken
CreateToken'
      { $sel:redirectUri:CreateToken' :: Maybe Text
redirectUri = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:refreshToken:CreateToken' :: Maybe Text
refreshToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:scope:CreateToken' :: Maybe [Text]
scope = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
        $sel:code:CreateToken' :: Maybe Text
code = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:clientId:CreateToken' :: Text
clientId = Text
pClientId_,
        $sel:clientSecret:CreateToken' :: Text
clientSecret = Text
pClientSecret_,
        $sel:grantType:CreateToken' :: Text
grantType = Text
pGrantType_,
        $sel:deviceCode:CreateToken' :: Text
deviceCode = Text
pDeviceCode_
      }

-- | The location of the application that will receive the authorization
-- code. Users authorize the service to send the request to this location.
createToken_redirectUri :: Lens.Lens' CreateToken (Prelude.Maybe Prelude.Text)
createToken_redirectUri :: (Maybe Text -> f (Maybe Text)) -> CreateToken -> f CreateToken
createToken_redirectUri = (CreateToken -> Maybe Text)
-> (CreateToken -> Maybe Text -> CreateToken)
-> Lens CreateToken CreateToken (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateToken' {Maybe Text
redirectUri :: Maybe Text
$sel:redirectUri:CreateToken' :: CreateToken -> Maybe Text
redirectUri} -> Maybe Text
redirectUri) (\s :: CreateToken
s@CreateToken' {} Maybe Text
a -> CreateToken
s {$sel:redirectUri:CreateToken' :: Maybe Text
redirectUri = Maybe Text
a} :: CreateToken)

-- | The token used to obtain an access token in the event that the access
-- token is invalid or expired. This token is not issued by the service.
createToken_refreshToken :: Lens.Lens' CreateToken (Prelude.Maybe Prelude.Text)
createToken_refreshToken :: (Maybe Text -> f (Maybe Text)) -> CreateToken -> f CreateToken
createToken_refreshToken = (CreateToken -> Maybe Text)
-> (CreateToken -> Maybe Text -> CreateToken)
-> Lens CreateToken CreateToken (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateToken' {Maybe Text
refreshToken :: Maybe Text
$sel:refreshToken:CreateToken' :: CreateToken -> Maybe Text
refreshToken} -> Maybe Text
refreshToken) (\s :: CreateToken
s@CreateToken' {} Maybe Text
a -> CreateToken
s {$sel:refreshToken:CreateToken' :: Maybe Text
refreshToken = Maybe Text
a} :: CreateToken)

-- | The list of scopes that is defined by the client. Upon authorization,
-- this list is used to restrict permissions when granting an access token.
createToken_scope :: Lens.Lens' CreateToken (Prelude.Maybe [Prelude.Text])
createToken_scope :: (Maybe [Text] -> f (Maybe [Text])) -> CreateToken -> f CreateToken
createToken_scope = (CreateToken -> Maybe [Text])
-> (CreateToken -> Maybe [Text] -> CreateToken)
-> Lens CreateToken CreateToken (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateToken' {Maybe [Text]
scope :: Maybe [Text]
$sel:scope:CreateToken' :: CreateToken -> Maybe [Text]
scope} -> Maybe [Text]
scope) (\s :: CreateToken
s@CreateToken' {} Maybe [Text]
a -> CreateToken
s {$sel:scope:CreateToken' :: Maybe [Text]
scope = Maybe [Text]
a} :: CreateToken) ((Maybe [Text] -> f (Maybe [Text]))
 -> CreateToken -> f CreateToken)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> CreateToken
-> f CreateToken
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The authorization code received from the authorization service. This
-- parameter is required to perform an authorization grant request to get
-- access to a token.
createToken_code :: Lens.Lens' CreateToken (Prelude.Maybe Prelude.Text)
createToken_code :: (Maybe Text -> f (Maybe Text)) -> CreateToken -> f CreateToken
createToken_code = (CreateToken -> Maybe Text)
-> (CreateToken -> Maybe Text -> CreateToken)
-> Lens CreateToken CreateToken (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateToken' {Maybe Text
code :: Maybe Text
$sel:code:CreateToken' :: CreateToken -> Maybe Text
code} -> Maybe Text
code) (\s :: CreateToken
s@CreateToken' {} Maybe Text
a -> CreateToken
s {$sel:code:CreateToken' :: Maybe Text
code = Maybe Text
a} :: CreateToken)

-- | The unique identifier string for each client. This value should come
-- from the persisted result of the RegisterClient API.
createToken_clientId :: Lens.Lens' CreateToken Prelude.Text
createToken_clientId :: (Text -> f Text) -> CreateToken -> f CreateToken
createToken_clientId = (CreateToken -> Text)
-> (CreateToken -> Text -> CreateToken)
-> Lens CreateToken CreateToken Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateToken' {Text
clientId :: Text
$sel:clientId:CreateToken' :: CreateToken -> Text
clientId} -> Text
clientId) (\s :: CreateToken
s@CreateToken' {} Text
a -> CreateToken
s {$sel:clientId:CreateToken' :: Text
clientId = Text
a} :: CreateToken)

-- | A secret string generated for the client. This value should come from
-- the persisted result of the RegisterClient API.
createToken_clientSecret :: Lens.Lens' CreateToken Prelude.Text
createToken_clientSecret :: (Text -> f Text) -> CreateToken -> f CreateToken
createToken_clientSecret = (CreateToken -> Text)
-> (CreateToken -> Text -> CreateToken)
-> Lens CreateToken CreateToken Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateToken' {Text
clientSecret :: Text
$sel:clientSecret:CreateToken' :: CreateToken -> Text
clientSecret} -> Text
clientSecret) (\s :: CreateToken
s@CreateToken' {} Text
a -> CreateToken
s {$sel:clientSecret:CreateToken' :: Text
clientSecret = Text
a} :: CreateToken)

-- | Supports grant types for authorization code, refresh token, and device
-- code request.
createToken_grantType :: Lens.Lens' CreateToken Prelude.Text
createToken_grantType :: (Text -> f Text) -> CreateToken -> f CreateToken
createToken_grantType = (CreateToken -> Text)
-> (CreateToken -> Text -> CreateToken)
-> Lens CreateToken CreateToken Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateToken' {Text
grantType :: Text
$sel:grantType:CreateToken' :: CreateToken -> Text
grantType} -> Text
grantType) (\s :: CreateToken
s@CreateToken' {} Text
a -> CreateToken
s {$sel:grantType:CreateToken' :: Text
grantType = Text
a} :: CreateToken)

-- | Used only when calling this API for the device code grant type. This
-- short-term code is used to identify this authentication attempt. This
-- should come from an in-memory reference to the result of the
-- StartDeviceAuthorization API.
createToken_deviceCode :: Lens.Lens' CreateToken Prelude.Text
createToken_deviceCode :: (Text -> f Text) -> CreateToken -> f CreateToken
createToken_deviceCode = (CreateToken -> Text)
-> (CreateToken -> Text -> CreateToken)
-> Lens CreateToken CreateToken Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateToken' {Text
deviceCode :: Text
$sel:deviceCode:CreateToken' :: CreateToken -> Text
deviceCode} -> Text
deviceCode) (\s :: CreateToken
s@CreateToken' {} Text
a -> CreateToken
s {$sel:deviceCode:CreateToken' :: Text
deviceCode = Text
a} :: CreateToken)

instance Core.AWSRequest CreateToken where
  type AWSResponse CreateToken = CreateTokenResponse
  request :: CreateToken -> Request CreateToken
request = Service -> CreateToken -> Request CreateToken
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateToken
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateToken)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateToken))
-> Logger
-> Service
-> Proxy CreateToken
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateToken)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe Int
-> Maybe Text
-> Maybe Text
-> Int
-> CreateTokenResponse
CreateTokenResponse'
            (Maybe Text
 -> Maybe Text
 -> Maybe Int
 -> Maybe Text
 -> Maybe Text
 -> Int
 -> CreateTokenResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe Int
      -> Maybe Text
      -> Maybe Text
      -> Int
      -> CreateTokenResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"accessToken")
            Either
  String
  (Maybe Text
   -> Maybe Int
   -> Maybe Text
   -> Maybe Text
   -> Int
   -> CreateTokenResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Int
      -> Maybe Text -> Maybe Text -> Int -> CreateTokenResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"refreshToken")
            Either
  String
  (Maybe Int
   -> Maybe Text -> Maybe Text -> Int -> CreateTokenResponse)
-> Either String (Maybe Int)
-> Either
     String (Maybe Text -> Maybe Text -> Int -> CreateTokenResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Int)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"expiresIn")
            Either
  String (Maybe Text -> Maybe Text -> Int -> CreateTokenResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> CreateTokenResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"tokenType")
            Either String (Maybe Text -> Int -> CreateTokenResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateTokenResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"idToken")
            Either String (Int -> CreateTokenResponse)
-> Either String Int -> Either String CreateTokenResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateToken

instance Prelude.NFData CreateToken

instance Core.ToHeaders CreateToken where
  toHeaders :: CreateToken -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateToken -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateToken where
  toJSON :: CreateToken -> Value
toJSON CreateToken' {Maybe [Text]
Maybe Text
Text
deviceCode :: Text
grantType :: Text
clientSecret :: Text
clientId :: Text
code :: Maybe Text
scope :: Maybe [Text]
refreshToken :: Maybe Text
redirectUri :: Maybe Text
$sel:deviceCode:CreateToken' :: CreateToken -> Text
$sel:grantType:CreateToken' :: CreateToken -> Text
$sel:clientSecret:CreateToken' :: CreateToken -> Text
$sel:clientId:CreateToken' :: CreateToken -> Text
$sel:code:CreateToken' :: CreateToken -> Maybe Text
$sel:scope:CreateToken' :: CreateToken -> Maybe [Text]
$sel:refreshToken:CreateToken' :: CreateToken -> Maybe Text
$sel:redirectUri:CreateToken' :: CreateToken -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"redirectUri" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
redirectUri,
            (Text
"refreshToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
refreshToken,
            (Text
"scope" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
scope,
            (Text
"code" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
code,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"clientId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clientId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"clientSecret" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clientSecret),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"grantType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
grantType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"deviceCode" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
deviceCode)
          ]
      )

instance Core.ToPath CreateToken where
  toPath :: CreateToken -> ByteString
toPath = ByteString -> CreateToken -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/token"

instance Core.ToQuery CreateToken where
  toQuery :: CreateToken -> QueryString
toQuery = QueryString -> CreateToken -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateTokenResponse' smart constructor.
data CreateTokenResponse = CreateTokenResponse'
  { -- | An opaque token to access AWS SSO resources assigned to a user.
    CreateTokenResponse -> Maybe Text
accessToken :: Prelude.Maybe Prelude.Text,
    -- | A token that, if present, can be used to refresh a previously issued
    -- access token that might have expired.
    CreateTokenResponse -> Maybe Text
refreshToken :: Prelude.Maybe Prelude.Text,
    -- | Indicates the time in seconds when an access token will expire.
    CreateTokenResponse -> Maybe Int
expiresIn :: Prelude.Maybe Prelude.Int,
    -- | Used to notify the client that the returned token is an access token.
    -- The supported type is @BearerToken@.
    CreateTokenResponse -> Maybe Text
tokenType :: Prelude.Maybe Prelude.Text,
    -- | The identifier of the user that associated with the access token, if
    -- present.
    CreateTokenResponse -> Maybe Text
idToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreateTokenResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateTokenResponse -> CreateTokenResponse -> Bool
(CreateTokenResponse -> CreateTokenResponse -> Bool)
-> (CreateTokenResponse -> CreateTokenResponse -> Bool)
-> Eq CreateTokenResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateTokenResponse -> CreateTokenResponse -> Bool
$c/= :: CreateTokenResponse -> CreateTokenResponse -> Bool
== :: CreateTokenResponse -> CreateTokenResponse -> Bool
$c== :: CreateTokenResponse -> CreateTokenResponse -> Bool
Prelude.Eq, ReadPrec [CreateTokenResponse]
ReadPrec CreateTokenResponse
Int -> ReadS CreateTokenResponse
ReadS [CreateTokenResponse]
(Int -> ReadS CreateTokenResponse)
-> ReadS [CreateTokenResponse]
-> ReadPrec CreateTokenResponse
-> ReadPrec [CreateTokenResponse]
-> Read CreateTokenResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateTokenResponse]
$creadListPrec :: ReadPrec [CreateTokenResponse]
readPrec :: ReadPrec CreateTokenResponse
$creadPrec :: ReadPrec CreateTokenResponse
readList :: ReadS [CreateTokenResponse]
$creadList :: ReadS [CreateTokenResponse]
readsPrec :: Int -> ReadS CreateTokenResponse
$creadsPrec :: Int -> ReadS CreateTokenResponse
Prelude.Read, Int -> CreateTokenResponse -> ShowS
[CreateTokenResponse] -> ShowS
CreateTokenResponse -> String
(Int -> CreateTokenResponse -> ShowS)
-> (CreateTokenResponse -> String)
-> ([CreateTokenResponse] -> ShowS)
-> Show CreateTokenResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateTokenResponse] -> ShowS
$cshowList :: [CreateTokenResponse] -> ShowS
show :: CreateTokenResponse -> String
$cshow :: CreateTokenResponse -> String
showsPrec :: Int -> CreateTokenResponse -> ShowS
$cshowsPrec :: Int -> CreateTokenResponse -> ShowS
Prelude.Show, (forall x. CreateTokenResponse -> Rep CreateTokenResponse x)
-> (forall x. Rep CreateTokenResponse x -> CreateTokenResponse)
-> Generic CreateTokenResponse
forall x. Rep CreateTokenResponse x -> CreateTokenResponse
forall x. CreateTokenResponse -> Rep CreateTokenResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateTokenResponse x -> CreateTokenResponse
$cfrom :: forall x. CreateTokenResponse -> Rep CreateTokenResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateTokenResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'accessToken', 'createTokenResponse_accessToken' - An opaque token to access AWS SSO resources assigned to a user.
--
-- 'refreshToken', 'createTokenResponse_refreshToken' - A token that, if present, can be used to refresh a previously issued
-- access token that might have expired.
--
-- 'expiresIn', 'createTokenResponse_expiresIn' - Indicates the time in seconds when an access token will expire.
--
-- 'tokenType', 'createTokenResponse_tokenType' - Used to notify the client that the returned token is an access token.
-- The supported type is @BearerToken@.
--
-- 'idToken', 'createTokenResponse_idToken' - The identifier of the user that associated with the access token, if
-- present.
--
-- 'httpStatus', 'createTokenResponse_httpStatus' - The response's http status code.
newCreateTokenResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateTokenResponse
newCreateTokenResponse :: Int -> CreateTokenResponse
newCreateTokenResponse Int
pHttpStatus_ =
  CreateTokenResponse' :: Maybe Text
-> Maybe Text
-> Maybe Int
-> Maybe Text
-> Maybe Text
-> Int
-> CreateTokenResponse
CreateTokenResponse'
    { $sel:accessToken:CreateTokenResponse' :: Maybe Text
accessToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:refreshToken:CreateTokenResponse' :: Maybe Text
refreshToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:expiresIn:CreateTokenResponse' :: Maybe Int
expiresIn = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:tokenType:CreateTokenResponse' :: Maybe Text
tokenType = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:idToken:CreateTokenResponse' :: Maybe Text
idToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateTokenResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An opaque token to access AWS SSO resources assigned to a user.
createTokenResponse_accessToken :: Lens.Lens' CreateTokenResponse (Prelude.Maybe Prelude.Text)
createTokenResponse_accessToken :: (Maybe Text -> f (Maybe Text))
-> CreateTokenResponse -> f CreateTokenResponse
createTokenResponse_accessToken = (CreateTokenResponse -> Maybe Text)
-> (CreateTokenResponse -> Maybe Text -> CreateTokenResponse)
-> Lens
     CreateTokenResponse CreateTokenResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTokenResponse' {Maybe Text
accessToken :: Maybe Text
$sel:accessToken:CreateTokenResponse' :: CreateTokenResponse -> Maybe Text
accessToken} -> Maybe Text
accessToken) (\s :: CreateTokenResponse
s@CreateTokenResponse' {} Maybe Text
a -> CreateTokenResponse
s {$sel:accessToken:CreateTokenResponse' :: Maybe Text
accessToken = Maybe Text
a} :: CreateTokenResponse)

-- | A token that, if present, can be used to refresh a previously issued
-- access token that might have expired.
createTokenResponse_refreshToken :: Lens.Lens' CreateTokenResponse (Prelude.Maybe Prelude.Text)
createTokenResponse_refreshToken :: (Maybe Text -> f (Maybe Text))
-> CreateTokenResponse -> f CreateTokenResponse
createTokenResponse_refreshToken = (CreateTokenResponse -> Maybe Text)
-> (CreateTokenResponse -> Maybe Text -> CreateTokenResponse)
-> Lens
     CreateTokenResponse CreateTokenResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTokenResponse' {Maybe Text
refreshToken :: Maybe Text
$sel:refreshToken:CreateTokenResponse' :: CreateTokenResponse -> Maybe Text
refreshToken} -> Maybe Text
refreshToken) (\s :: CreateTokenResponse
s@CreateTokenResponse' {} Maybe Text
a -> CreateTokenResponse
s {$sel:refreshToken:CreateTokenResponse' :: Maybe Text
refreshToken = Maybe Text
a} :: CreateTokenResponse)

-- | Indicates the time in seconds when an access token will expire.
createTokenResponse_expiresIn :: Lens.Lens' CreateTokenResponse (Prelude.Maybe Prelude.Int)
createTokenResponse_expiresIn :: (Maybe Int -> f (Maybe Int))
-> CreateTokenResponse -> f CreateTokenResponse
createTokenResponse_expiresIn = (CreateTokenResponse -> Maybe Int)
-> (CreateTokenResponse -> Maybe Int -> CreateTokenResponse)
-> Lens
     CreateTokenResponse CreateTokenResponse (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTokenResponse' {Maybe Int
expiresIn :: Maybe Int
$sel:expiresIn:CreateTokenResponse' :: CreateTokenResponse -> Maybe Int
expiresIn} -> Maybe Int
expiresIn) (\s :: CreateTokenResponse
s@CreateTokenResponse' {} Maybe Int
a -> CreateTokenResponse
s {$sel:expiresIn:CreateTokenResponse' :: Maybe Int
expiresIn = Maybe Int
a} :: CreateTokenResponse)

-- | Used to notify the client that the returned token is an access token.
-- The supported type is @BearerToken@.
createTokenResponse_tokenType :: Lens.Lens' CreateTokenResponse (Prelude.Maybe Prelude.Text)
createTokenResponse_tokenType :: (Maybe Text -> f (Maybe Text))
-> CreateTokenResponse -> f CreateTokenResponse
createTokenResponse_tokenType = (CreateTokenResponse -> Maybe Text)
-> (CreateTokenResponse -> Maybe Text -> CreateTokenResponse)
-> Lens
     CreateTokenResponse CreateTokenResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTokenResponse' {Maybe Text
tokenType :: Maybe Text
$sel:tokenType:CreateTokenResponse' :: CreateTokenResponse -> Maybe Text
tokenType} -> Maybe Text
tokenType) (\s :: CreateTokenResponse
s@CreateTokenResponse' {} Maybe Text
a -> CreateTokenResponse
s {$sel:tokenType:CreateTokenResponse' :: Maybe Text
tokenType = Maybe Text
a} :: CreateTokenResponse)

-- | The identifier of the user that associated with the access token, if
-- present.
createTokenResponse_idToken :: Lens.Lens' CreateTokenResponse (Prelude.Maybe Prelude.Text)
createTokenResponse_idToken :: (Maybe Text -> f (Maybe Text))
-> CreateTokenResponse -> f CreateTokenResponse
createTokenResponse_idToken = (CreateTokenResponse -> Maybe Text)
-> (CreateTokenResponse -> Maybe Text -> CreateTokenResponse)
-> Lens
     CreateTokenResponse CreateTokenResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTokenResponse' {Maybe Text
idToken :: Maybe Text
$sel:idToken:CreateTokenResponse' :: CreateTokenResponse -> Maybe Text
idToken} -> Maybe Text
idToken) (\s :: CreateTokenResponse
s@CreateTokenResponse' {} Maybe Text
a -> CreateTokenResponse
s {$sel:idToken:CreateTokenResponse' :: Maybe Text
idToken = Maybe Text
a} :: CreateTokenResponse)

-- | The response's http status code.
createTokenResponse_httpStatus :: Lens.Lens' CreateTokenResponse Prelude.Int
createTokenResponse_httpStatus :: (Int -> f Int) -> CreateTokenResponse -> f CreateTokenResponse
createTokenResponse_httpStatus = (CreateTokenResponse -> Int)
-> (CreateTokenResponse -> Int -> CreateTokenResponse)
-> Lens CreateTokenResponse CreateTokenResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTokenResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateTokenResponse' :: CreateTokenResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateTokenResponse
s@CreateTokenResponse' {} Int
a -> CreateTokenResponse
s {$sel:httpStatus:CreateTokenResponse' :: Int
httpStatus = Int
a} :: CreateTokenResponse)

instance Prelude.NFData CreateTokenResponse