{-# 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.Connect.Types.Credentials
-- 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.Connect.Types.Credentials where

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

-- | Contains credentials to use for federation.
--
-- /See:/ 'newCredentials' smart constructor.
data Credentials = Credentials'
  { -- | A token generated with an expiration time for the session a user is
    -- logged in to Amazon Connect.
    Credentials -> Maybe POSIX
accessTokenExpiration :: Prelude.Maybe Core.POSIX,
    -- | An access token generated for a federated user to access Amazon Connect.
    Credentials -> Maybe (Sensitive Text)
accessToken :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | Renews a token generated for a user to access the Amazon Connect
    -- instance.
    Credentials -> Maybe (Sensitive Text)
refreshToken :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | Renews the expiration timer for a generated token.
    Credentials -> Maybe POSIX
refreshTokenExpiration :: Prelude.Maybe Core.POSIX
  }
  deriving (Credentials -> Credentials -> Bool
(Credentials -> Credentials -> Bool)
-> (Credentials -> Credentials -> Bool) -> Eq Credentials
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Credentials -> Credentials -> Bool
$c/= :: Credentials -> Credentials -> Bool
== :: Credentials -> Credentials -> Bool
$c== :: Credentials -> Credentials -> Bool
Prelude.Eq, Int -> Credentials -> ShowS
[Credentials] -> ShowS
Credentials -> String
(Int -> Credentials -> ShowS)
-> (Credentials -> String)
-> ([Credentials] -> ShowS)
-> Show Credentials
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Credentials] -> ShowS
$cshowList :: [Credentials] -> ShowS
show :: Credentials -> String
$cshow :: Credentials -> String
showsPrec :: Int -> Credentials -> ShowS
$cshowsPrec :: Int -> Credentials -> ShowS
Prelude.Show, (forall x. Credentials -> Rep Credentials x)
-> (forall x. Rep Credentials x -> Credentials)
-> Generic Credentials
forall x. Rep Credentials x -> Credentials
forall x. Credentials -> Rep Credentials x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Credentials x -> Credentials
$cfrom :: forall x. Credentials -> Rep Credentials x
Prelude.Generic)

-- |
-- Create a value of 'Credentials' 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:
--
-- 'accessTokenExpiration', 'credentials_accessTokenExpiration' - A token generated with an expiration time for the session a user is
-- logged in to Amazon Connect.
--
-- 'accessToken', 'credentials_accessToken' - An access token generated for a federated user to access Amazon Connect.
--
-- 'refreshToken', 'credentials_refreshToken' - Renews a token generated for a user to access the Amazon Connect
-- instance.
--
-- 'refreshTokenExpiration', 'credentials_refreshTokenExpiration' - Renews the expiration timer for a generated token.
newCredentials ::
  Credentials
newCredentials :: Credentials
newCredentials =
  Credentials' :: Maybe POSIX
-> Maybe (Sensitive Text)
-> Maybe (Sensitive Text)
-> Maybe POSIX
-> Credentials
Credentials'
    { $sel:accessTokenExpiration:Credentials' :: Maybe POSIX
accessTokenExpiration =
        Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:accessToken:Credentials' :: Maybe (Sensitive Text)
accessToken = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:refreshToken:Credentials' :: Maybe (Sensitive Text)
refreshToken = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:refreshTokenExpiration:Credentials' :: Maybe POSIX
refreshTokenExpiration = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | A token generated with an expiration time for the session a user is
-- logged in to Amazon Connect.
credentials_accessTokenExpiration :: Lens.Lens' Credentials (Prelude.Maybe Prelude.UTCTime)
credentials_accessTokenExpiration :: (Maybe UTCTime -> f (Maybe UTCTime))
-> Credentials -> f Credentials
credentials_accessTokenExpiration = (Credentials -> Maybe POSIX)
-> (Credentials -> Maybe POSIX -> Credentials)
-> Lens Credentials Credentials (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Credentials' {Maybe POSIX
accessTokenExpiration :: Maybe POSIX
$sel:accessTokenExpiration:Credentials' :: Credentials -> Maybe POSIX
accessTokenExpiration} -> Maybe POSIX
accessTokenExpiration) (\s :: Credentials
s@Credentials' {} Maybe POSIX
a -> Credentials
s {$sel:accessTokenExpiration:Credentials' :: Maybe POSIX
accessTokenExpiration = Maybe POSIX
a} :: Credentials) ((Maybe POSIX -> f (Maybe POSIX)) -> Credentials -> f Credentials)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Credentials
-> f Credentials
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | An access token generated for a federated user to access Amazon Connect.
credentials_accessToken :: Lens.Lens' Credentials (Prelude.Maybe Prelude.Text)
credentials_accessToken :: (Maybe Text -> f (Maybe Text)) -> Credentials -> f Credentials
credentials_accessToken = (Credentials -> Maybe (Sensitive Text))
-> (Credentials -> Maybe (Sensitive Text) -> Credentials)
-> Lens
     Credentials
     Credentials
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Credentials' {Maybe (Sensitive Text)
accessToken :: Maybe (Sensitive Text)
$sel:accessToken:Credentials' :: Credentials -> Maybe (Sensitive Text)
accessToken} -> Maybe (Sensitive Text)
accessToken) (\s :: Credentials
s@Credentials' {} Maybe (Sensitive Text)
a -> Credentials
s {$sel:accessToken:Credentials' :: Maybe (Sensitive Text)
accessToken = Maybe (Sensitive Text)
a} :: Credentials) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> Credentials -> f Credentials)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> Credentials
-> f Credentials
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive 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 (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | Renews a token generated for a user to access the Amazon Connect
-- instance.
credentials_refreshToken :: Lens.Lens' Credentials (Prelude.Maybe Prelude.Text)
credentials_refreshToken :: (Maybe Text -> f (Maybe Text)) -> Credentials -> f Credentials
credentials_refreshToken = (Credentials -> Maybe (Sensitive Text))
-> (Credentials -> Maybe (Sensitive Text) -> Credentials)
-> Lens
     Credentials
     Credentials
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Credentials' {Maybe (Sensitive Text)
refreshToken :: Maybe (Sensitive Text)
$sel:refreshToken:Credentials' :: Credentials -> Maybe (Sensitive Text)
refreshToken} -> Maybe (Sensitive Text)
refreshToken) (\s :: Credentials
s@Credentials' {} Maybe (Sensitive Text)
a -> Credentials
s {$sel:refreshToken:Credentials' :: Maybe (Sensitive Text)
refreshToken = Maybe (Sensitive Text)
a} :: Credentials) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> Credentials -> f Credentials)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> Credentials
-> f Credentials
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive 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 (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | Renews the expiration timer for a generated token.
credentials_refreshTokenExpiration :: Lens.Lens' Credentials (Prelude.Maybe Prelude.UTCTime)
credentials_refreshTokenExpiration :: (Maybe UTCTime -> f (Maybe UTCTime))
-> Credentials -> f Credentials
credentials_refreshTokenExpiration = (Credentials -> Maybe POSIX)
-> (Credentials -> Maybe POSIX -> Credentials)
-> Lens Credentials Credentials (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Credentials' {Maybe POSIX
refreshTokenExpiration :: Maybe POSIX
$sel:refreshTokenExpiration:Credentials' :: Credentials -> Maybe POSIX
refreshTokenExpiration} -> Maybe POSIX
refreshTokenExpiration) (\s :: Credentials
s@Credentials' {} Maybe POSIX
a -> Credentials
s {$sel:refreshTokenExpiration:Credentials' :: Maybe POSIX
refreshTokenExpiration = Maybe POSIX
a} :: Credentials) ((Maybe POSIX -> f (Maybe POSIX)) -> Credentials -> f Credentials)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Credentials
-> f Credentials
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Core.FromJSON Credentials where
  parseJSON :: Value -> Parser Credentials
parseJSON =
    String
-> (Object -> Parser Credentials) -> Value -> Parser Credentials
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Credentials"
      ( \Object
x ->
          Maybe POSIX
-> Maybe (Sensitive Text)
-> Maybe (Sensitive Text)
-> Maybe POSIX
-> Credentials
Credentials'
            (Maybe POSIX
 -> Maybe (Sensitive Text)
 -> Maybe (Sensitive Text)
 -> Maybe POSIX
 -> Credentials)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe (Sensitive Text)
      -> Maybe (Sensitive Text) -> Maybe POSIX -> Credentials)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AccessTokenExpiration")
            Parser
  (Maybe (Sensitive Text)
   -> Maybe (Sensitive Text) -> Maybe POSIX -> Credentials)
-> Parser (Maybe (Sensitive Text))
-> Parser (Maybe (Sensitive Text) -> Maybe POSIX -> Credentials)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Sensitive Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AccessToken")
            Parser (Maybe (Sensitive Text) -> Maybe POSIX -> Credentials)
-> Parser (Maybe (Sensitive Text))
-> Parser (Maybe POSIX -> Credentials)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Sensitive Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RefreshToken")
            Parser (Maybe POSIX -> Credentials)
-> Parser (Maybe POSIX) -> Parser Credentials
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RefreshTokenExpiration")
      )

instance Prelude.Hashable Credentials

instance Prelude.NFData Credentials