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

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

-- |
-- Module      : Amazonka.CognitoIdentity.Types.CognitoIdentityProvider
-- 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)
module Amazonka.CognitoIdentity.Types.CognitoIdentityProvider where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A provider representing an Amazon Cognito user pool and its client ID.
--
-- /See:/ 'newCognitoIdentityProvider' smart constructor.
data CognitoIdentityProvider = CognitoIdentityProvider'
  { -- | The client ID for the Amazon Cognito user pool.
    CognitoIdentityProvider -> Maybe Text
clientId :: Prelude.Maybe Prelude.Text,
    -- | TRUE if server-side token validation is enabled for the identity
    -- provider’s token.
    --
    -- Once you set @ServerSideTokenCheck@ to TRUE for an identity pool, that
    -- identity pool will check with the integrated user pools to make sure
    -- that the user has not been globally signed out or deleted before the
    -- identity pool provides an OIDC token or AWS credentials for the user.
    --
    -- If the user is signed out or deleted, the identity pool will return a
    -- 400 Not Authorized error.
    CognitoIdentityProvider -> Maybe Bool
serverSideTokenCheck :: Prelude.Maybe Prelude.Bool,
    -- | The provider name for an Amazon Cognito user pool. For example,
    -- @cognito-idp.us-east-1.amazonaws.com\/us-east-1_123456789@.
    CognitoIdentityProvider -> Maybe Text
providerName :: Prelude.Maybe Prelude.Text
  }
  deriving (CognitoIdentityProvider -> CognitoIdentityProvider -> Bool
(CognitoIdentityProvider -> CognitoIdentityProvider -> Bool)
-> (CognitoIdentityProvider -> CognitoIdentityProvider -> Bool)
-> Eq CognitoIdentityProvider
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CognitoIdentityProvider -> CognitoIdentityProvider -> Bool
$c/= :: CognitoIdentityProvider -> CognitoIdentityProvider -> Bool
== :: CognitoIdentityProvider -> CognitoIdentityProvider -> Bool
$c== :: CognitoIdentityProvider -> CognitoIdentityProvider -> Bool
Prelude.Eq, ReadPrec [CognitoIdentityProvider]
ReadPrec CognitoIdentityProvider
Int -> ReadS CognitoIdentityProvider
ReadS [CognitoIdentityProvider]
(Int -> ReadS CognitoIdentityProvider)
-> ReadS [CognitoIdentityProvider]
-> ReadPrec CognitoIdentityProvider
-> ReadPrec [CognitoIdentityProvider]
-> Read CognitoIdentityProvider
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CognitoIdentityProvider]
$creadListPrec :: ReadPrec [CognitoIdentityProvider]
readPrec :: ReadPrec CognitoIdentityProvider
$creadPrec :: ReadPrec CognitoIdentityProvider
readList :: ReadS [CognitoIdentityProvider]
$creadList :: ReadS [CognitoIdentityProvider]
readsPrec :: Int -> ReadS CognitoIdentityProvider
$creadsPrec :: Int -> ReadS CognitoIdentityProvider
Prelude.Read, Int -> CognitoIdentityProvider -> ShowS
[CognitoIdentityProvider] -> ShowS
CognitoIdentityProvider -> String
(Int -> CognitoIdentityProvider -> ShowS)
-> (CognitoIdentityProvider -> String)
-> ([CognitoIdentityProvider] -> ShowS)
-> Show CognitoIdentityProvider
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CognitoIdentityProvider] -> ShowS
$cshowList :: [CognitoIdentityProvider] -> ShowS
show :: CognitoIdentityProvider -> String
$cshow :: CognitoIdentityProvider -> String
showsPrec :: Int -> CognitoIdentityProvider -> ShowS
$cshowsPrec :: Int -> CognitoIdentityProvider -> ShowS
Prelude.Show, (forall x.
 CognitoIdentityProvider -> Rep CognitoIdentityProvider x)
-> (forall x.
    Rep CognitoIdentityProvider x -> CognitoIdentityProvider)
-> Generic CognitoIdentityProvider
forall x. Rep CognitoIdentityProvider x -> CognitoIdentityProvider
forall x. CognitoIdentityProvider -> Rep CognitoIdentityProvider x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CognitoIdentityProvider x -> CognitoIdentityProvider
$cfrom :: forall x. CognitoIdentityProvider -> Rep CognitoIdentityProvider x
Prelude.Generic)

-- |
-- Create a value of 'CognitoIdentityProvider' 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:
--
-- 'clientId', 'cognitoIdentityProvider_clientId' - The client ID for the Amazon Cognito user pool.
--
-- 'serverSideTokenCheck', 'cognitoIdentityProvider_serverSideTokenCheck' - TRUE if server-side token validation is enabled for the identity
-- provider’s token.
--
-- Once you set @ServerSideTokenCheck@ to TRUE for an identity pool, that
-- identity pool will check with the integrated user pools to make sure
-- that the user has not been globally signed out or deleted before the
-- identity pool provides an OIDC token or AWS credentials for the user.
--
-- If the user is signed out or deleted, the identity pool will return a
-- 400 Not Authorized error.
--
-- 'providerName', 'cognitoIdentityProvider_providerName' - The provider name for an Amazon Cognito user pool. For example,
-- @cognito-idp.us-east-1.amazonaws.com\/us-east-1_123456789@.
newCognitoIdentityProvider ::
  CognitoIdentityProvider
newCognitoIdentityProvider :: CognitoIdentityProvider
newCognitoIdentityProvider =
  CognitoIdentityProvider' :: Maybe Text -> Maybe Bool -> Maybe Text -> CognitoIdentityProvider
CognitoIdentityProvider'
    { $sel:clientId:CognitoIdentityProvider' :: Maybe Text
clientId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:serverSideTokenCheck:CognitoIdentityProvider' :: Maybe Bool
serverSideTokenCheck = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:providerName:CognitoIdentityProvider' :: Maybe Text
providerName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The client ID for the Amazon Cognito user pool.
cognitoIdentityProvider_clientId :: Lens.Lens' CognitoIdentityProvider (Prelude.Maybe Prelude.Text)
cognitoIdentityProvider_clientId :: (Maybe Text -> f (Maybe Text))
-> CognitoIdentityProvider -> f CognitoIdentityProvider
cognitoIdentityProvider_clientId = (CognitoIdentityProvider -> Maybe Text)
-> (CognitoIdentityProvider
    -> Maybe Text -> CognitoIdentityProvider)
-> Lens
     CognitoIdentityProvider
     CognitoIdentityProvider
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoIdentityProvider' {Maybe Text
clientId :: Maybe Text
$sel:clientId:CognitoIdentityProvider' :: CognitoIdentityProvider -> Maybe Text
clientId} -> Maybe Text
clientId) (\s :: CognitoIdentityProvider
s@CognitoIdentityProvider' {} Maybe Text
a -> CognitoIdentityProvider
s {$sel:clientId:CognitoIdentityProvider' :: Maybe Text
clientId = Maybe Text
a} :: CognitoIdentityProvider)

-- | TRUE if server-side token validation is enabled for the identity
-- provider’s token.
--
-- Once you set @ServerSideTokenCheck@ to TRUE for an identity pool, that
-- identity pool will check with the integrated user pools to make sure
-- that the user has not been globally signed out or deleted before the
-- identity pool provides an OIDC token or AWS credentials for the user.
--
-- If the user is signed out or deleted, the identity pool will return a
-- 400 Not Authorized error.
cognitoIdentityProvider_serverSideTokenCheck :: Lens.Lens' CognitoIdentityProvider (Prelude.Maybe Prelude.Bool)
cognitoIdentityProvider_serverSideTokenCheck :: (Maybe Bool -> f (Maybe Bool))
-> CognitoIdentityProvider -> f CognitoIdentityProvider
cognitoIdentityProvider_serverSideTokenCheck = (CognitoIdentityProvider -> Maybe Bool)
-> (CognitoIdentityProvider
    -> Maybe Bool -> CognitoIdentityProvider)
-> Lens
     CognitoIdentityProvider
     CognitoIdentityProvider
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoIdentityProvider' {Maybe Bool
serverSideTokenCheck :: Maybe Bool
$sel:serverSideTokenCheck:CognitoIdentityProvider' :: CognitoIdentityProvider -> Maybe Bool
serverSideTokenCheck} -> Maybe Bool
serverSideTokenCheck) (\s :: CognitoIdentityProvider
s@CognitoIdentityProvider' {} Maybe Bool
a -> CognitoIdentityProvider
s {$sel:serverSideTokenCheck:CognitoIdentityProvider' :: Maybe Bool
serverSideTokenCheck = Maybe Bool
a} :: CognitoIdentityProvider)

-- | The provider name for an Amazon Cognito user pool. For example,
-- @cognito-idp.us-east-1.amazonaws.com\/us-east-1_123456789@.
cognitoIdentityProvider_providerName :: Lens.Lens' CognitoIdentityProvider (Prelude.Maybe Prelude.Text)
cognitoIdentityProvider_providerName :: (Maybe Text -> f (Maybe Text))
-> CognitoIdentityProvider -> f CognitoIdentityProvider
cognitoIdentityProvider_providerName = (CognitoIdentityProvider -> Maybe Text)
-> (CognitoIdentityProvider
    -> Maybe Text -> CognitoIdentityProvider)
-> Lens
     CognitoIdentityProvider
     CognitoIdentityProvider
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CognitoIdentityProvider' {Maybe Text
providerName :: Maybe Text
$sel:providerName:CognitoIdentityProvider' :: CognitoIdentityProvider -> Maybe Text
providerName} -> Maybe Text
providerName) (\s :: CognitoIdentityProvider
s@CognitoIdentityProvider' {} Maybe Text
a -> CognitoIdentityProvider
s {$sel:providerName:CognitoIdentityProvider' :: Maybe Text
providerName = Maybe Text
a} :: CognitoIdentityProvider)

instance Core.FromJSON CognitoIdentityProvider where
  parseJSON :: Value -> Parser CognitoIdentityProvider
parseJSON =
    String
-> (Object -> Parser CognitoIdentityProvider)
-> Value
-> Parser CognitoIdentityProvider
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CognitoIdentityProvider"
      ( \Object
x ->
          Maybe Text -> Maybe Bool -> Maybe Text -> CognitoIdentityProvider
CognitoIdentityProvider'
            (Maybe Text -> Maybe Bool -> Maybe Text -> CognitoIdentityProvider)
-> Parser (Maybe Text)
-> Parser (Maybe Bool -> Maybe Text -> CognitoIdentityProvider)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ClientId")
            Parser (Maybe Bool -> Maybe Text -> CognitoIdentityProvider)
-> Parser (Maybe Bool)
-> Parser (Maybe Text -> CognitoIdentityProvider)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ServerSideTokenCheck")
            Parser (Maybe Text -> CognitoIdentityProvider)
-> Parser (Maybe Text) -> Parser CognitoIdentityProvider
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ProviderName")
      )

instance Prelude.Hashable CognitoIdentityProvider

instance Prelude.NFData CognitoIdentityProvider

instance Core.ToJSON CognitoIdentityProvider where
  toJSON :: CognitoIdentityProvider -> Value
toJSON CognitoIdentityProvider' {Maybe Bool
Maybe Text
providerName :: Maybe Text
serverSideTokenCheck :: Maybe Bool
clientId :: Maybe Text
$sel:providerName:CognitoIdentityProvider' :: CognitoIdentityProvider -> Maybe Text
$sel:serverSideTokenCheck:CognitoIdentityProvider' :: CognitoIdentityProvider -> Maybe Bool
$sel:clientId:CognitoIdentityProvider' :: CognitoIdentityProvider -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ClientId" 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
clientId,
            (Text
"ServerSideTokenCheck" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
serverSideTokenCheck,
            (Text
"ProviderName" 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
providerName
          ]
      )