{-# 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.AppSync.Types.OpenIDConnectConfig
-- 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.AppSync.Types.OpenIDConnectConfig where

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

-- | Describes an OpenID Connect configuration.
--
-- /See:/ 'newOpenIDConnectConfig' smart constructor.
data OpenIDConnectConfig = OpenIDConnectConfig'
  { -- | The number of milliseconds a token is valid after being authenticated.
    OpenIDConnectConfig -> Maybe Integer
authTTL :: Prelude.Maybe Prelude.Integer,
    -- | The client identifier of the Relying party at the OpenID identity
    -- provider. This identifier is typically obtained when the Relying party
    -- is registered with the OpenID identity provider. You can specify a
    -- regular expression so the AppSync can validate against multiple client
    -- identifiers at a time.
    OpenIDConnectConfig -> Maybe Text
clientId :: Prelude.Maybe Prelude.Text,
    -- | The number of milliseconds a token is valid after being issued to a
    -- user.
    OpenIDConnectConfig -> Maybe Integer
iatTTL :: Prelude.Maybe Prelude.Integer,
    -- | The issuer for the OpenID Connect configuration. The issuer returned by
    -- discovery must exactly match the value of @iss@ in the ID token.
    OpenIDConnectConfig -> Text
issuer :: Prelude.Text
  }
  deriving (OpenIDConnectConfig -> OpenIDConnectConfig -> Bool
(OpenIDConnectConfig -> OpenIDConnectConfig -> Bool)
-> (OpenIDConnectConfig -> OpenIDConnectConfig -> Bool)
-> Eq OpenIDConnectConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OpenIDConnectConfig -> OpenIDConnectConfig -> Bool
$c/= :: OpenIDConnectConfig -> OpenIDConnectConfig -> Bool
== :: OpenIDConnectConfig -> OpenIDConnectConfig -> Bool
$c== :: OpenIDConnectConfig -> OpenIDConnectConfig -> Bool
Prelude.Eq, ReadPrec [OpenIDConnectConfig]
ReadPrec OpenIDConnectConfig
Int -> ReadS OpenIDConnectConfig
ReadS [OpenIDConnectConfig]
(Int -> ReadS OpenIDConnectConfig)
-> ReadS [OpenIDConnectConfig]
-> ReadPrec OpenIDConnectConfig
-> ReadPrec [OpenIDConnectConfig]
-> Read OpenIDConnectConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OpenIDConnectConfig]
$creadListPrec :: ReadPrec [OpenIDConnectConfig]
readPrec :: ReadPrec OpenIDConnectConfig
$creadPrec :: ReadPrec OpenIDConnectConfig
readList :: ReadS [OpenIDConnectConfig]
$creadList :: ReadS [OpenIDConnectConfig]
readsPrec :: Int -> ReadS OpenIDConnectConfig
$creadsPrec :: Int -> ReadS OpenIDConnectConfig
Prelude.Read, Int -> OpenIDConnectConfig -> ShowS
[OpenIDConnectConfig] -> ShowS
OpenIDConnectConfig -> String
(Int -> OpenIDConnectConfig -> ShowS)
-> (OpenIDConnectConfig -> String)
-> ([OpenIDConnectConfig] -> ShowS)
-> Show OpenIDConnectConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OpenIDConnectConfig] -> ShowS
$cshowList :: [OpenIDConnectConfig] -> ShowS
show :: OpenIDConnectConfig -> String
$cshow :: OpenIDConnectConfig -> String
showsPrec :: Int -> OpenIDConnectConfig -> ShowS
$cshowsPrec :: Int -> OpenIDConnectConfig -> ShowS
Prelude.Show, (forall x. OpenIDConnectConfig -> Rep OpenIDConnectConfig x)
-> (forall x. Rep OpenIDConnectConfig x -> OpenIDConnectConfig)
-> Generic OpenIDConnectConfig
forall x. Rep OpenIDConnectConfig x -> OpenIDConnectConfig
forall x. OpenIDConnectConfig -> Rep OpenIDConnectConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OpenIDConnectConfig x -> OpenIDConnectConfig
$cfrom :: forall x. OpenIDConnectConfig -> Rep OpenIDConnectConfig x
Prelude.Generic)

-- |
-- Create a value of 'OpenIDConnectConfig' 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:
--
-- 'authTTL', 'openIDConnectConfig_authTTL' - The number of milliseconds a token is valid after being authenticated.
--
-- 'clientId', 'openIDConnectConfig_clientId' - The client identifier of the Relying party at the OpenID identity
-- provider. This identifier is typically obtained when the Relying party
-- is registered with the OpenID identity provider. You can specify a
-- regular expression so the AppSync can validate against multiple client
-- identifiers at a time.
--
-- 'iatTTL', 'openIDConnectConfig_iatTTL' - The number of milliseconds a token is valid after being issued to a
-- user.
--
-- 'issuer', 'openIDConnectConfig_issuer' - The issuer for the OpenID Connect configuration. The issuer returned by
-- discovery must exactly match the value of @iss@ in the ID token.
newOpenIDConnectConfig ::
  -- | 'issuer'
  Prelude.Text ->
  OpenIDConnectConfig
newOpenIDConnectConfig :: Text -> OpenIDConnectConfig
newOpenIDConnectConfig Text
pIssuer_ =
  OpenIDConnectConfig' :: Maybe Integer
-> Maybe Text -> Maybe Integer -> Text -> OpenIDConnectConfig
OpenIDConnectConfig'
    { $sel:authTTL:OpenIDConnectConfig' :: Maybe Integer
authTTL = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:clientId:OpenIDConnectConfig' :: Maybe Text
clientId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:iatTTL:OpenIDConnectConfig' :: Maybe Integer
iatTTL = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:issuer:OpenIDConnectConfig' :: Text
issuer = Text
pIssuer_
    }

-- | The number of milliseconds a token is valid after being authenticated.
openIDConnectConfig_authTTL :: Lens.Lens' OpenIDConnectConfig (Prelude.Maybe Prelude.Integer)
openIDConnectConfig_authTTL :: (Maybe Integer -> f (Maybe Integer))
-> OpenIDConnectConfig -> f OpenIDConnectConfig
openIDConnectConfig_authTTL = (OpenIDConnectConfig -> Maybe Integer)
-> (OpenIDConnectConfig -> Maybe Integer -> OpenIDConnectConfig)
-> Lens
     OpenIDConnectConfig
     OpenIDConnectConfig
     (Maybe Integer)
     (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OpenIDConnectConfig' {Maybe Integer
authTTL :: Maybe Integer
$sel:authTTL:OpenIDConnectConfig' :: OpenIDConnectConfig -> Maybe Integer
authTTL} -> Maybe Integer
authTTL) (\s :: OpenIDConnectConfig
s@OpenIDConnectConfig' {} Maybe Integer
a -> OpenIDConnectConfig
s {$sel:authTTL:OpenIDConnectConfig' :: Maybe Integer
authTTL = Maybe Integer
a} :: OpenIDConnectConfig)

-- | The client identifier of the Relying party at the OpenID identity
-- provider. This identifier is typically obtained when the Relying party
-- is registered with the OpenID identity provider. You can specify a
-- regular expression so the AppSync can validate against multiple client
-- identifiers at a time.
openIDConnectConfig_clientId :: Lens.Lens' OpenIDConnectConfig (Prelude.Maybe Prelude.Text)
openIDConnectConfig_clientId :: (Maybe Text -> f (Maybe Text))
-> OpenIDConnectConfig -> f OpenIDConnectConfig
openIDConnectConfig_clientId = (OpenIDConnectConfig -> Maybe Text)
-> (OpenIDConnectConfig -> Maybe Text -> OpenIDConnectConfig)
-> Lens
     OpenIDConnectConfig OpenIDConnectConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OpenIDConnectConfig' {Maybe Text
clientId :: Maybe Text
$sel:clientId:OpenIDConnectConfig' :: OpenIDConnectConfig -> Maybe Text
clientId} -> Maybe Text
clientId) (\s :: OpenIDConnectConfig
s@OpenIDConnectConfig' {} Maybe Text
a -> OpenIDConnectConfig
s {$sel:clientId:OpenIDConnectConfig' :: Maybe Text
clientId = Maybe Text
a} :: OpenIDConnectConfig)

-- | The number of milliseconds a token is valid after being issued to a
-- user.
openIDConnectConfig_iatTTL :: Lens.Lens' OpenIDConnectConfig (Prelude.Maybe Prelude.Integer)
openIDConnectConfig_iatTTL :: (Maybe Integer -> f (Maybe Integer))
-> OpenIDConnectConfig -> f OpenIDConnectConfig
openIDConnectConfig_iatTTL = (OpenIDConnectConfig -> Maybe Integer)
-> (OpenIDConnectConfig -> Maybe Integer -> OpenIDConnectConfig)
-> Lens
     OpenIDConnectConfig
     OpenIDConnectConfig
     (Maybe Integer)
     (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OpenIDConnectConfig' {Maybe Integer
iatTTL :: Maybe Integer
$sel:iatTTL:OpenIDConnectConfig' :: OpenIDConnectConfig -> Maybe Integer
iatTTL} -> Maybe Integer
iatTTL) (\s :: OpenIDConnectConfig
s@OpenIDConnectConfig' {} Maybe Integer
a -> OpenIDConnectConfig
s {$sel:iatTTL:OpenIDConnectConfig' :: Maybe Integer
iatTTL = Maybe Integer
a} :: OpenIDConnectConfig)

-- | The issuer for the OpenID Connect configuration. The issuer returned by
-- discovery must exactly match the value of @iss@ in the ID token.
openIDConnectConfig_issuer :: Lens.Lens' OpenIDConnectConfig Prelude.Text
openIDConnectConfig_issuer :: (Text -> f Text) -> OpenIDConnectConfig -> f OpenIDConnectConfig
openIDConnectConfig_issuer = (OpenIDConnectConfig -> Text)
-> (OpenIDConnectConfig -> Text -> OpenIDConnectConfig)
-> Lens OpenIDConnectConfig OpenIDConnectConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OpenIDConnectConfig' {Text
issuer :: Text
$sel:issuer:OpenIDConnectConfig' :: OpenIDConnectConfig -> Text
issuer} -> Text
issuer) (\s :: OpenIDConnectConfig
s@OpenIDConnectConfig' {} Text
a -> OpenIDConnectConfig
s {$sel:issuer:OpenIDConnectConfig' :: Text
issuer = Text
a} :: OpenIDConnectConfig)

instance Core.FromJSON OpenIDConnectConfig where
  parseJSON :: Value -> Parser OpenIDConnectConfig
parseJSON =
    String
-> (Object -> Parser OpenIDConnectConfig)
-> Value
-> Parser OpenIDConnectConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OpenIDConnectConfig"
      ( \Object
x ->
          Maybe Integer
-> Maybe Text -> Maybe Integer -> Text -> OpenIDConnectConfig
OpenIDConnectConfig'
            (Maybe Integer
 -> Maybe Text -> Maybe Integer -> Text -> OpenIDConnectConfig)
-> Parser (Maybe Integer)
-> Parser
     (Maybe Text -> Maybe Integer -> Text -> OpenIDConnectConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"authTTL")
            Parser (Maybe Text -> Maybe Integer -> Text -> OpenIDConnectConfig)
-> Parser (Maybe Text)
-> Parser (Maybe Integer -> Text -> OpenIDConnectConfig)
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
"clientId")
            Parser (Maybe Integer -> Text -> OpenIDConnectConfig)
-> Parser (Maybe Integer) -> Parser (Text -> OpenIDConnectConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"iatTTL")
            Parser (Text -> OpenIDConnectConfig)
-> Parser Text -> Parser OpenIDConnectConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"issuer")
      )

instance Prelude.Hashable OpenIDConnectConfig

instance Prelude.NFData OpenIDConnectConfig

instance Core.ToJSON OpenIDConnectConfig where
  toJSON :: OpenIDConnectConfig -> Value
toJSON OpenIDConnectConfig' {Maybe Integer
Maybe Text
Text
issuer :: Text
iatTTL :: Maybe Integer
clientId :: Maybe Text
authTTL :: Maybe Integer
$sel:issuer:OpenIDConnectConfig' :: OpenIDConnectConfig -> Text
$sel:iatTTL:OpenIDConnectConfig' :: OpenIDConnectConfig -> Maybe Integer
$sel:clientId:OpenIDConnectConfig' :: OpenIDConnectConfig -> Maybe Text
$sel:authTTL:OpenIDConnectConfig' :: OpenIDConnectConfig -> Maybe Integer
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"authTTL" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
authTTL,
            (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
"iatTTL" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
iatTTL,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"issuer" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
issuer)
          ]
      )