{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ApiGatewayV2.Types.JWTConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:audience:JWTConfiguration' :: Maybe [Text]
audience = forall a. Maybe a
Prelude.Nothing,
      $sel:issuer:JWTConfiguration' :: Maybe Text
issuer = 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 :: Lens' JWTConfiguration (Maybe [Text])
jWTConfiguration_audience = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' JWTConfiguration (Maybe Text)
jWTConfiguration_issuer = 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 Data.FromJSON JWTConfiguration where
  parseJSON :: Value -> Parser JWTConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"JWTConfiguration"
      ( \Object
x ->
          Maybe [Text] -> Maybe Text -> JWTConfiguration
JWTConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"audience" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"issuer")
      )

instance Prelude.Hashable JWTConfiguration where
  hashWithSalt :: Int -> JWTConfiguration -> Int
hashWithSalt Int
_salt JWTConfiguration' {Maybe [Text]
Maybe Text
issuer :: Maybe Text
audience :: Maybe [Text]
$sel:issuer:JWTConfiguration' :: JWTConfiguration -> Maybe Text
$sel:audience:JWTConfiguration' :: JWTConfiguration -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
audience
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
issuer

instance Prelude.NFData JWTConfiguration where
  rnf :: JWTConfiguration -> ()
rnf JWTConfiguration' {Maybe [Text]
Maybe Text
issuer :: Maybe Text
audience :: Maybe [Text]
$sel:issuer:JWTConfiguration' :: JWTConfiguration -> Maybe Text
$sel:audience:JWTConfiguration' :: JWTConfiguration -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
audience
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
issuer

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"audience" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
audience,
            (Key
"issuer" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
issuer
          ]
      )