{-# 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.ApiGatewayV2.Types.JWTConfiguration
-- 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.ApiGatewayV2.Types.JWTConfiguration where

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

-- | Represents the configuration of a JWT authorizer. Required for the JWT
-- authorizer type. Supported only for HTTP APIs.
--
-- /See:/ 'newJWTConfiguration' smart constructor.
data JWTConfiguration = JWTConfiguration'
  { -- | A list of the intended recipients of the JWT. A valid JWT must provide
    -- an aud that matches at least one entry in this list. See
    -- <https://tools.ietf.org/html/rfc7519#section-4.1.3 RFC 7519>. Supported
    -- only for HTTP APIs.
    JWTConfiguration -> Maybe [Text]
audience :: Prelude.Maybe [Prelude.Text],
    -- | The base domain of the identity provider that issues JSON Web Tokens.
    -- For example, an Amazon Cognito user pool has the following format:
    -- https:\/\/cognito-idp.{region}.amazonaws.com\/{userPoolId} . Required
    -- for the JWT authorizer type. Supported only for HTTP APIs.
    JWTConfiguration -> Maybe Text
issuer :: Prelude.Maybe Prelude.Text
  }
  deriving (JWTConfiguration -> JWTConfiguration -> Bool
(JWTConfiguration -> JWTConfiguration -> Bool)
-> (JWTConfiguration -> JWTConfiguration -> Bool)
-> Eq JWTConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JWTConfiguration -> JWTConfiguration -> Bool
$c/= :: JWTConfiguration -> JWTConfiguration -> Bool
== :: JWTConfiguration -> JWTConfiguration -> Bool
$c== :: JWTConfiguration -> JWTConfiguration -> Bool
Prelude.Eq, ReadPrec [JWTConfiguration]
ReadPrec JWTConfiguration
Int -> ReadS JWTConfiguration
ReadS [JWTConfiguration]
(Int -> ReadS JWTConfiguration)
-> ReadS [JWTConfiguration]
-> ReadPrec JWTConfiguration
-> ReadPrec [JWTConfiguration]
-> Read JWTConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [JWTConfiguration]
$creadListPrec :: ReadPrec [JWTConfiguration]
readPrec :: ReadPrec JWTConfiguration
$creadPrec :: ReadPrec JWTConfiguration
readList :: ReadS [JWTConfiguration]
$creadList :: ReadS [JWTConfiguration]
readsPrec :: Int -> ReadS JWTConfiguration
$creadsPrec :: Int -> ReadS JWTConfiguration
Prelude.Read, Int -> JWTConfiguration -> ShowS
[JWTConfiguration] -> ShowS
JWTConfiguration -> String
(Int -> JWTConfiguration -> ShowS)
-> (JWTConfiguration -> String)
-> ([JWTConfiguration] -> ShowS)
-> Show JWTConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JWTConfiguration] -> ShowS
$cshowList :: [JWTConfiguration] -> ShowS
show :: JWTConfiguration -> String
$cshow :: JWTConfiguration -> String
showsPrec :: Int -> JWTConfiguration -> ShowS
$cshowsPrec :: Int -> JWTConfiguration -> ShowS
Prelude.Show, (forall x. JWTConfiguration -> Rep JWTConfiguration x)
-> (forall x. Rep JWTConfiguration x -> JWTConfiguration)
-> Generic JWTConfiguration
forall x. Rep JWTConfiguration x -> JWTConfiguration
forall x. JWTConfiguration -> Rep JWTConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep JWTConfiguration x -> JWTConfiguration
$cfrom :: forall x. JWTConfiguration -> Rep JWTConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'JWTConfiguration' 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:
--
-- 'audience', 'jWTConfiguration_audience' - A list of the intended recipients of the JWT. A valid JWT must provide
-- an aud that matches at least one entry in this list. See
-- <https://tools.ietf.org/html/rfc7519#section-4.1.3 RFC 7519>. Supported
-- only for HTTP APIs.
--
-- 'issuer', 'jWTConfiguration_issuer' - The base domain of the identity provider that issues JSON Web Tokens.
-- For example, an Amazon Cognito user pool has the following format:
-- https:\/\/cognito-idp.{region}.amazonaws.com\/{userPoolId} . Required
-- for the JWT authorizer type. Supported only for HTTP APIs.
newJWTConfiguration ::
  JWTConfiguration
newJWTConfiguration :: JWTConfiguration
newJWTConfiguration =
  JWTConfiguration' :: Maybe [Text] -> Maybe Text -> JWTConfiguration
JWTConfiguration'
    { $sel:audience:JWTConfiguration' :: Maybe [Text]
audience = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:issuer:JWTConfiguration' :: Maybe Text
issuer = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | A list of the intended recipients of the JWT. A valid JWT must provide
-- an aud that matches at least one entry in this list. See
-- <https://tools.ietf.org/html/rfc7519#section-4.1.3 RFC 7519>. Supported
-- only for HTTP APIs.
jWTConfiguration_audience :: Lens.Lens' JWTConfiguration (Prelude.Maybe [Prelude.Text])
jWTConfiguration_audience :: (Maybe [Text] -> f (Maybe [Text]))
-> JWTConfiguration -> f JWTConfiguration
jWTConfiguration_audience = (JWTConfiguration -> Maybe [Text])
-> (JWTConfiguration -> Maybe [Text] -> JWTConfiguration)
-> Lens
     JWTConfiguration JWTConfiguration (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JWTConfiguration' {Maybe [Text]
audience :: Maybe [Text]
$sel:audience:JWTConfiguration' :: JWTConfiguration -> Maybe [Text]
audience} -> Maybe [Text]
audience) (\s :: JWTConfiguration
s@JWTConfiguration' {} Maybe [Text]
a -> JWTConfiguration
s {$sel:audience:JWTConfiguration' :: Maybe [Text]
audience = Maybe [Text]
a} :: JWTConfiguration) ((Maybe [Text] -> f (Maybe [Text]))
 -> JWTConfiguration -> f JWTConfiguration)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> JWTConfiguration
-> f JWTConfiguration
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 base domain of the identity provider that issues JSON Web Tokens.
-- For example, an Amazon Cognito user pool has the following format:
-- https:\/\/cognito-idp.{region}.amazonaws.com\/{userPoolId} . Required
-- for the JWT authorizer type. Supported only for HTTP APIs.
jWTConfiguration_issuer :: Lens.Lens' JWTConfiguration (Prelude.Maybe Prelude.Text)
jWTConfiguration_issuer :: (Maybe Text -> f (Maybe Text))
-> JWTConfiguration -> f JWTConfiguration
jWTConfiguration_issuer = (JWTConfiguration -> Maybe Text)
-> (JWTConfiguration -> Maybe Text -> JWTConfiguration)
-> Lens JWTConfiguration JWTConfiguration (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JWTConfiguration' {Maybe Text
issuer :: Maybe Text
$sel:issuer:JWTConfiguration' :: JWTConfiguration -> Maybe Text
issuer} -> Maybe Text
issuer) (\s :: JWTConfiguration
s@JWTConfiguration' {} Maybe Text
a -> JWTConfiguration
s {$sel:issuer:JWTConfiguration' :: Maybe Text
issuer = Maybe Text
a} :: JWTConfiguration)

instance Core.FromJSON JWTConfiguration where
  parseJSON :: Value -> Parser JWTConfiguration
parseJSON =
    String
-> (Object -> Parser JWTConfiguration)
-> Value
-> Parser JWTConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"JWTConfiguration"
      ( \Object
x ->
          Maybe [Text] -> Maybe Text -> JWTConfiguration
JWTConfiguration'
            (Maybe [Text] -> Maybe Text -> JWTConfiguration)
-> Parser (Maybe [Text]) -> Parser (Maybe Text -> JWTConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"audience" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> JWTConfiguration)
-> Parser (Maybe Text) -> Parser JWTConfiguration
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
"issuer")
      )

instance Prelude.Hashable JWTConfiguration

instance Prelude.NFData JWTConfiguration

instance Core.ToJSON JWTConfiguration where
  toJSON :: JWTConfiguration -> Value
toJSON JWTConfiguration' {Maybe [Text]
Maybe Text
issuer :: Maybe Text
audience :: Maybe [Text]
$sel:issuer:JWTConfiguration' :: JWTConfiguration -> Maybe Text
$sel:audience:JWTConfiguration' :: JWTConfiguration -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"audience" 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]
audience,
            (Text
"issuer" 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
issuer
          ]
      )