{-# 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.AdditionalAuthenticationProvider
-- 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.AdditionalAuthenticationProvider where

import Amazonka.AppSync.Types.AuthenticationType
import Amazonka.AppSync.Types.CognitoUserPoolConfig
import Amazonka.AppSync.Types.LambdaAuthorizerConfig
import Amazonka.AppSync.Types.OpenIDConnectConfig
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an additional authentication provider.
--
-- /See:/ 'newAdditionalAuthenticationProvider' smart constructor.
data AdditionalAuthenticationProvider = AdditionalAuthenticationProvider'
  { -- | The OpenID Connect configuration.
    AdditionalAuthenticationProvider -> Maybe OpenIDConnectConfig
openIDConnectConfig :: Prelude.Maybe OpenIDConnectConfig,
    -- | Configuration for Amazon Web Services Lambda function authorization.
    AdditionalAuthenticationProvider -> Maybe LambdaAuthorizerConfig
lambdaAuthorizerConfig :: Prelude.Maybe LambdaAuthorizerConfig,
    -- | The Amazon Cognito user pool configuration.
    AdditionalAuthenticationProvider -> Maybe CognitoUserPoolConfig
userPoolConfig :: Prelude.Maybe CognitoUserPoolConfig,
    -- | The authentication type: API key, Identity and Access Management, OIDC,
    -- Amazon Cognito user pools, or Amazon Web Services Lambda.
    AdditionalAuthenticationProvider -> Maybe AuthenticationType
authenticationType :: Prelude.Maybe AuthenticationType
  }
  deriving (AdditionalAuthenticationProvider
-> AdditionalAuthenticationProvider -> Bool
(AdditionalAuthenticationProvider
 -> AdditionalAuthenticationProvider -> Bool)
-> (AdditionalAuthenticationProvider
    -> AdditionalAuthenticationProvider -> Bool)
-> Eq AdditionalAuthenticationProvider
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AdditionalAuthenticationProvider
-> AdditionalAuthenticationProvider -> Bool
$c/= :: AdditionalAuthenticationProvider
-> AdditionalAuthenticationProvider -> Bool
== :: AdditionalAuthenticationProvider
-> AdditionalAuthenticationProvider -> Bool
$c== :: AdditionalAuthenticationProvider
-> AdditionalAuthenticationProvider -> Bool
Prelude.Eq, ReadPrec [AdditionalAuthenticationProvider]
ReadPrec AdditionalAuthenticationProvider
Int -> ReadS AdditionalAuthenticationProvider
ReadS [AdditionalAuthenticationProvider]
(Int -> ReadS AdditionalAuthenticationProvider)
-> ReadS [AdditionalAuthenticationProvider]
-> ReadPrec AdditionalAuthenticationProvider
-> ReadPrec [AdditionalAuthenticationProvider]
-> Read AdditionalAuthenticationProvider
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AdditionalAuthenticationProvider]
$creadListPrec :: ReadPrec [AdditionalAuthenticationProvider]
readPrec :: ReadPrec AdditionalAuthenticationProvider
$creadPrec :: ReadPrec AdditionalAuthenticationProvider
readList :: ReadS [AdditionalAuthenticationProvider]
$creadList :: ReadS [AdditionalAuthenticationProvider]
readsPrec :: Int -> ReadS AdditionalAuthenticationProvider
$creadsPrec :: Int -> ReadS AdditionalAuthenticationProvider
Prelude.Read, Int -> AdditionalAuthenticationProvider -> ShowS
[AdditionalAuthenticationProvider] -> ShowS
AdditionalAuthenticationProvider -> String
(Int -> AdditionalAuthenticationProvider -> ShowS)
-> (AdditionalAuthenticationProvider -> String)
-> ([AdditionalAuthenticationProvider] -> ShowS)
-> Show AdditionalAuthenticationProvider
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AdditionalAuthenticationProvider] -> ShowS
$cshowList :: [AdditionalAuthenticationProvider] -> ShowS
show :: AdditionalAuthenticationProvider -> String
$cshow :: AdditionalAuthenticationProvider -> String
showsPrec :: Int -> AdditionalAuthenticationProvider -> ShowS
$cshowsPrec :: Int -> AdditionalAuthenticationProvider -> ShowS
Prelude.Show, (forall x.
 AdditionalAuthenticationProvider
 -> Rep AdditionalAuthenticationProvider x)
-> (forall x.
    Rep AdditionalAuthenticationProvider x
    -> AdditionalAuthenticationProvider)
-> Generic AdditionalAuthenticationProvider
forall x.
Rep AdditionalAuthenticationProvider x
-> AdditionalAuthenticationProvider
forall x.
AdditionalAuthenticationProvider
-> Rep AdditionalAuthenticationProvider x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AdditionalAuthenticationProvider x
-> AdditionalAuthenticationProvider
$cfrom :: forall x.
AdditionalAuthenticationProvider
-> Rep AdditionalAuthenticationProvider x
Prelude.Generic)

-- |
-- Create a value of 'AdditionalAuthenticationProvider' 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:
--
-- 'openIDConnectConfig', 'additionalAuthenticationProvider_openIDConnectConfig' - The OpenID Connect configuration.
--
-- 'lambdaAuthorizerConfig', 'additionalAuthenticationProvider_lambdaAuthorizerConfig' - Configuration for Amazon Web Services Lambda function authorization.
--
-- 'userPoolConfig', 'additionalAuthenticationProvider_userPoolConfig' - The Amazon Cognito user pool configuration.
--
-- 'authenticationType', 'additionalAuthenticationProvider_authenticationType' - The authentication type: API key, Identity and Access Management, OIDC,
-- Amazon Cognito user pools, or Amazon Web Services Lambda.
newAdditionalAuthenticationProvider ::
  AdditionalAuthenticationProvider
newAdditionalAuthenticationProvider :: AdditionalAuthenticationProvider
newAdditionalAuthenticationProvider =
  AdditionalAuthenticationProvider' :: Maybe OpenIDConnectConfig
-> Maybe LambdaAuthorizerConfig
-> Maybe CognitoUserPoolConfig
-> Maybe AuthenticationType
-> AdditionalAuthenticationProvider
AdditionalAuthenticationProvider'
    { $sel:openIDConnectConfig:AdditionalAuthenticationProvider' :: Maybe OpenIDConnectConfig
openIDConnectConfig =
        Maybe OpenIDConnectConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:lambdaAuthorizerConfig:AdditionalAuthenticationProvider' :: Maybe LambdaAuthorizerConfig
lambdaAuthorizerConfig = Maybe LambdaAuthorizerConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:userPoolConfig:AdditionalAuthenticationProvider' :: Maybe CognitoUserPoolConfig
userPoolConfig = Maybe CognitoUserPoolConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:authenticationType:AdditionalAuthenticationProvider' :: Maybe AuthenticationType
authenticationType = Maybe AuthenticationType
forall a. Maybe a
Prelude.Nothing
    }

-- | The OpenID Connect configuration.
additionalAuthenticationProvider_openIDConnectConfig :: Lens.Lens' AdditionalAuthenticationProvider (Prelude.Maybe OpenIDConnectConfig)
additionalAuthenticationProvider_openIDConnectConfig :: (Maybe OpenIDConnectConfig -> f (Maybe OpenIDConnectConfig))
-> AdditionalAuthenticationProvider
-> f AdditionalAuthenticationProvider
additionalAuthenticationProvider_openIDConnectConfig = (AdditionalAuthenticationProvider -> Maybe OpenIDConnectConfig)
-> (AdditionalAuthenticationProvider
    -> Maybe OpenIDConnectConfig -> AdditionalAuthenticationProvider)
-> Lens
     AdditionalAuthenticationProvider
     AdditionalAuthenticationProvider
     (Maybe OpenIDConnectConfig)
     (Maybe OpenIDConnectConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AdditionalAuthenticationProvider' {Maybe OpenIDConnectConfig
openIDConnectConfig :: Maybe OpenIDConnectConfig
$sel:openIDConnectConfig:AdditionalAuthenticationProvider' :: AdditionalAuthenticationProvider -> Maybe OpenIDConnectConfig
openIDConnectConfig} -> Maybe OpenIDConnectConfig
openIDConnectConfig) (\s :: AdditionalAuthenticationProvider
s@AdditionalAuthenticationProvider' {} Maybe OpenIDConnectConfig
a -> AdditionalAuthenticationProvider
s {$sel:openIDConnectConfig:AdditionalAuthenticationProvider' :: Maybe OpenIDConnectConfig
openIDConnectConfig = Maybe OpenIDConnectConfig
a} :: AdditionalAuthenticationProvider)

-- | Configuration for Amazon Web Services Lambda function authorization.
additionalAuthenticationProvider_lambdaAuthorizerConfig :: Lens.Lens' AdditionalAuthenticationProvider (Prelude.Maybe LambdaAuthorizerConfig)
additionalAuthenticationProvider_lambdaAuthorizerConfig :: (Maybe LambdaAuthorizerConfig -> f (Maybe LambdaAuthorizerConfig))
-> AdditionalAuthenticationProvider
-> f AdditionalAuthenticationProvider
additionalAuthenticationProvider_lambdaAuthorizerConfig = (AdditionalAuthenticationProvider -> Maybe LambdaAuthorizerConfig)
-> (AdditionalAuthenticationProvider
    -> Maybe LambdaAuthorizerConfig
    -> AdditionalAuthenticationProvider)
-> Lens
     AdditionalAuthenticationProvider
     AdditionalAuthenticationProvider
     (Maybe LambdaAuthorizerConfig)
     (Maybe LambdaAuthorizerConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AdditionalAuthenticationProvider' {Maybe LambdaAuthorizerConfig
lambdaAuthorizerConfig :: Maybe LambdaAuthorizerConfig
$sel:lambdaAuthorizerConfig:AdditionalAuthenticationProvider' :: AdditionalAuthenticationProvider -> Maybe LambdaAuthorizerConfig
lambdaAuthorizerConfig} -> Maybe LambdaAuthorizerConfig
lambdaAuthorizerConfig) (\s :: AdditionalAuthenticationProvider
s@AdditionalAuthenticationProvider' {} Maybe LambdaAuthorizerConfig
a -> AdditionalAuthenticationProvider
s {$sel:lambdaAuthorizerConfig:AdditionalAuthenticationProvider' :: Maybe LambdaAuthorizerConfig
lambdaAuthorizerConfig = Maybe LambdaAuthorizerConfig
a} :: AdditionalAuthenticationProvider)

-- | The Amazon Cognito user pool configuration.
additionalAuthenticationProvider_userPoolConfig :: Lens.Lens' AdditionalAuthenticationProvider (Prelude.Maybe CognitoUserPoolConfig)
additionalAuthenticationProvider_userPoolConfig :: (Maybe CognitoUserPoolConfig -> f (Maybe CognitoUserPoolConfig))
-> AdditionalAuthenticationProvider
-> f AdditionalAuthenticationProvider
additionalAuthenticationProvider_userPoolConfig = (AdditionalAuthenticationProvider -> Maybe CognitoUserPoolConfig)
-> (AdditionalAuthenticationProvider
    -> Maybe CognitoUserPoolConfig -> AdditionalAuthenticationProvider)
-> Lens
     AdditionalAuthenticationProvider
     AdditionalAuthenticationProvider
     (Maybe CognitoUserPoolConfig)
     (Maybe CognitoUserPoolConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AdditionalAuthenticationProvider' {Maybe CognitoUserPoolConfig
userPoolConfig :: Maybe CognitoUserPoolConfig
$sel:userPoolConfig:AdditionalAuthenticationProvider' :: AdditionalAuthenticationProvider -> Maybe CognitoUserPoolConfig
userPoolConfig} -> Maybe CognitoUserPoolConfig
userPoolConfig) (\s :: AdditionalAuthenticationProvider
s@AdditionalAuthenticationProvider' {} Maybe CognitoUserPoolConfig
a -> AdditionalAuthenticationProvider
s {$sel:userPoolConfig:AdditionalAuthenticationProvider' :: Maybe CognitoUserPoolConfig
userPoolConfig = Maybe CognitoUserPoolConfig
a} :: AdditionalAuthenticationProvider)

-- | The authentication type: API key, Identity and Access Management, OIDC,
-- Amazon Cognito user pools, or Amazon Web Services Lambda.
additionalAuthenticationProvider_authenticationType :: Lens.Lens' AdditionalAuthenticationProvider (Prelude.Maybe AuthenticationType)
additionalAuthenticationProvider_authenticationType :: (Maybe AuthenticationType -> f (Maybe AuthenticationType))
-> AdditionalAuthenticationProvider
-> f AdditionalAuthenticationProvider
additionalAuthenticationProvider_authenticationType = (AdditionalAuthenticationProvider -> Maybe AuthenticationType)
-> (AdditionalAuthenticationProvider
    -> Maybe AuthenticationType -> AdditionalAuthenticationProvider)
-> Lens
     AdditionalAuthenticationProvider
     AdditionalAuthenticationProvider
     (Maybe AuthenticationType)
     (Maybe AuthenticationType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AdditionalAuthenticationProvider' {Maybe AuthenticationType
authenticationType :: Maybe AuthenticationType
$sel:authenticationType:AdditionalAuthenticationProvider' :: AdditionalAuthenticationProvider -> Maybe AuthenticationType
authenticationType} -> Maybe AuthenticationType
authenticationType) (\s :: AdditionalAuthenticationProvider
s@AdditionalAuthenticationProvider' {} Maybe AuthenticationType
a -> AdditionalAuthenticationProvider
s {$sel:authenticationType:AdditionalAuthenticationProvider' :: Maybe AuthenticationType
authenticationType = Maybe AuthenticationType
a} :: AdditionalAuthenticationProvider)

instance
  Core.FromJSON
    AdditionalAuthenticationProvider
  where
  parseJSON :: Value -> Parser AdditionalAuthenticationProvider
parseJSON =
    String
-> (Object -> Parser AdditionalAuthenticationProvider)
-> Value
-> Parser AdditionalAuthenticationProvider
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AdditionalAuthenticationProvider"
      ( \Object
x ->
          Maybe OpenIDConnectConfig
-> Maybe LambdaAuthorizerConfig
-> Maybe CognitoUserPoolConfig
-> Maybe AuthenticationType
-> AdditionalAuthenticationProvider
AdditionalAuthenticationProvider'
            (Maybe OpenIDConnectConfig
 -> Maybe LambdaAuthorizerConfig
 -> Maybe CognitoUserPoolConfig
 -> Maybe AuthenticationType
 -> AdditionalAuthenticationProvider)
-> Parser (Maybe OpenIDConnectConfig)
-> Parser
     (Maybe LambdaAuthorizerConfig
      -> Maybe CognitoUserPoolConfig
      -> Maybe AuthenticationType
      -> AdditionalAuthenticationProvider)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe OpenIDConnectConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"openIDConnectConfig")
            Parser
  (Maybe LambdaAuthorizerConfig
   -> Maybe CognitoUserPoolConfig
   -> Maybe AuthenticationType
   -> AdditionalAuthenticationProvider)
-> Parser (Maybe LambdaAuthorizerConfig)
-> Parser
     (Maybe CognitoUserPoolConfig
      -> Maybe AuthenticationType -> AdditionalAuthenticationProvider)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe LambdaAuthorizerConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"lambdaAuthorizerConfig")
            Parser
  (Maybe CognitoUserPoolConfig
   -> Maybe AuthenticationType -> AdditionalAuthenticationProvider)
-> Parser (Maybe CognitoUserPoolConfig)
-> Parser
     (Maybe AuthenticationType -> AdditionalAuthenticationProvider)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe CognitoUserPoolConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"userPoolConfig")
            Parser
  (Maybe AuthenticationType -> AdditionalAuthenticationProvider)
-> Parser (Maybe AuthenticationType)
-> Parser AdditionalAuthenticationProvider
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe AuthenticationType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"authenticationType")
      )

instance
  Prelude.Hashable
    AdditionalAuthenticationProvider

instance
  Prelude.NFData
    AdditionalAuthenticationProvider

instance Core.ToJSON AdditionalAuthenticationProvider where
  toJSON :: AdditionalAuthenticationProvider -> Value
toJSON AdditionalAuthenticationProvider' {Maybe AuthenticationType
Maybe CognitoUserPoolConfig
Maybe LambdaAuthorizerConfig
Maybe OpenIDConnectConfig
authenticationType :: Maybe AuthenticationType
userPoolConfig :: Maybe CognitoUserPoolConfig
lambdaAuthorizerConfig :: Maybe LambdaAuthorizerConfig
openIDConnectConfig :: Maybe OpenIDConnectConfig
$sel:authenticationType:AdditionalAuthenticationProvider' :: AdditionalAuthenticationProvider -> Maybe AuthenticationType
$sel:userPoolConfig:AdditionalAuthenticationProvider' :: AdditionalAuthenticationProvider -> Maybe CognitoUserPoolConfig
$sel:lambdaAuthorizerConfig:AdditionalAuthenticationProvider' :: AdditionalAuthenticationProvider -> Maybe LambdaAuthorizerConfig
$sel:openIDConnectConfig:AdditionalAuthenticationProvider' :: AdditionalAuthenticationProvider -> Maybe OpenIDConnectConfig
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"openIDConnectConfig" Text -> OpenIDConnectConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (OpenIDConnectConfig -> Pair)
-> Maybe OpenIDConnectConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OpenIDConnectConfig
openIDConnectConfig,
            (Text
"lambdaAuthorizerConfig" Text -> LambdaAuthorizerConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (LambdaAuthorizerConfig -> Pair)
-> Maybe LambdaAuthorizerConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe LambdaAuthorizerConfig
lambdaAuthorizerConfig,
            (Text
"userPoolConfig" Text -> CognitoUserPoolConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (CognitoUserPoolConfig -> Pair)
-> Maybe CognitoUserPoolConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CognitoUserPoolConfig
userPoolConfig,
            (Text
"authenticationType" Text -> AuthenticationType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (AuthenticationType -> Pair)
-> Maybe AuthenticationType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AuthenticationType
authenticationType
          ]
      )