{-# 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.AppFlow.Types.OAuthCredentials
-- 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.AppFlow.Types.OAuthCredentials where

import Amazonka.AppFlow.Types.ConnectorOAuthRequest
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The OAuth credentials required for OAuth type authentication.
--
-- /See:/ 'newOAuthCredentials' smart constructor.
data OAuthCredentials = OAuthCredentials'
  { -- | The access token used to access protected SAPOData resources.
    OAuthCredentials -> Maybe (Sensitive Text)
accessToken :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | The refresh token used to refresh expired access token.
    OAuthCredentials -> Maybe Text
refreshToken :: Prelude.Maybe Prelude.Text,
    -- | The OAuth requirement needed to request security tokens from the
    -- connector endpoint.
    OAuthCredentials -> Maybe ConnectorOAuthRequest
oAuthRequest :: Prelude.Maybe ConnectorOAuthRequest,
    -- | The identifier for the desired client.
    OAuthCredentials -> Text
clientId :: Prelude.Text,
    -- | The client secret used by the OAuth client to authenticate to the
    -- authorization server.
    OAuthCredentials -> Sensitive Text
clientSecret :: Core.Sensitive Prelude.Text
  }
  deriving (OAuthCredentials -> OAuthCredentials -> Bool
(OAuthCredentials -> OAuthCredentials -> Bool)
-> (OAuthCredentials -> OAuthCredentials -> Bool)
-> Eq OAuthCredentials
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OAuthCredentials -> OAuthCredentials -> Bool
$c/= :: OAuthCredentials -> OAuthCredentials -> Bool
== :: OAuthCredentials -> OAuthCredentials -> Bool
$c== :: OAuthCredentials -> OAuthCredentials -> Bool
Prelude.Eq, Int -> OAuthCredentials -> ShowS
[OAuthCredentials] -> ShowS
OAuthCredentials -> String
(Int -> OAuthCredentials -> ShowS)
-> (OAuthCredentials -> String)
-> ([OAuthCredentials] -> ShowS)
-> Show OAuthCredentials
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OAuthCredentials] -> ShowS
$cshowList :: [OAuthCredentials] -> ShowS
show :: OAuthCredentials -> String
$cshow :: OAuthCredentials -> String
showsPrec :: Int -> OAuthCredentials -> ShowS
$cshowsPrec :: Int -> OAuthCredentials -> ShowS
Prelude.Show, (forall x. OAuthCredentials -> Rep OAuthCredentials x)
-> (forall x. Rep OAuthCredentials x -> OAuthCredentials)
-> Generic OAuthCredentials
forall x. Rep OAuthCredentials x -> OAuthCredentials
forall x. OAuthCredentials -> Rep OAuthCredentials x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OAuthCredentials x -> OAuthCredentials
$cfrom :: forall x. OAuthCredentials -> Rep OAuthCredentials x
Prelude.Generic)

-- |
-- Create a value of 'OAuthCredentials' 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:
--
-- 'accessToken', 'oAuthCredentials_accessToken' - The access token used to access protected SAPOData resources.
--
-- 'refreshToken', 'oAuthCredentials_refreshToken' - The refresh token used to refresh expired access token.
--
-- 'oAuthRequest', 'oAuthCredentials_oAuthRequest' - The OAuth requirement needed to request security tokens from the
-- connector endpoint.
--
-- 'clientId', 'oAuthCredentials_clientId' - The identifier for the desired client.
--
-- 'clientSecret', 'oAuthCredentials_clientSecret' - The client secret used by the OAuth client to authenticate to the
-- authorization server.
newOAuthCredentials ::
  -- | 'clientId'
  Prelude.Text ->
  -- | 'clientSecret'
  Prelude.Text ->
  OAuthCredentials
newOAuthCredentials :: Text -> Text -> OAuthCredentials
newOAuthCredentials Text
pClientId_ Text
pClientSecret_ =
  OAuthCredentials' :: Maybe (Sensitive Text)
-> Maybe Text
-> Maybe ConnectorOAuthRequest
-> Text
-> Sensitive Text
-> OAuthCredentials
OAuthCredentials'
    { $sel:accessToken:OAuthCredentials' :: Maybe (Sensitive Text)
accessToken = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:refreshToken:OAuthCredentials' :: Maybe Text
refreshToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:oAuthRequest:OAuthCredentials' :: Maybe ConnectorOAuthRequest
oAuthRequest = Maybe ConnectorOAuthRequest
forall a. Maybe a
Prelude.Nothing,
      $sel:clientId:OAuthCredentials' :: Text
clientId = Text
pClientId_,
      $sel:clientSecret:OAuthCredentials' :: Sensitive Text
clientSecret = Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pClientSecret_
    }

-- | The access token used to access protected SAPOData resources.
oAuthCredentials_accessToken :: Lens.Lens' OAuthCredentials (Prelude.Maybe Prelude.Text)
oAuthCredentials_accessToken :: (Maybe Text -> f (Maybe Text))
-> OAuthCredentials -> f OAuthCredentials
oAuthCredentials_accessToken = (OAuthCredentials -> Maybe (Sensitive Text))
-> (OAuthCredentials -> Maybe (Sensitive Text) -> OAuthCredentials)
-> Lens
     OAuthCredentials
     OAuthCredentials
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OAuthCredentials' {Maybe (Sensitive Text)
accessToken :: Maybe (Sensitive Text)
$sel:accessToken:OAuthCredentials' :: OAuthCredentials -> Maybe (Sensitive Text)
accessToken} -> Maybe (Sensitive Text)
accessToken) (\s :: OAuthCredentials
s@OAuthCredentials' {} Maybe (Sensitive Text)
a -> OAuthCredentials
s {$sel:accessToken:OAuthCredentials' :: Maybe (Sensitive Text)
accessToken = Maybe (Sensitive Text)
a} :: OAuthCredentials) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> OAuthCredentials -> f OAuthCredentials)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> OAuthCredentials
-> f OAuthCredentials
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

-- | The refresh token used to refresh expired access token.
oAuthCredentials_refreshToken :: Lens.Lens' OAuthCredentials (Prelude.Maybe Prelude.Text)
oAuthCredentials_refreshToken :: (Maybe Text -> f (Maybe Text))
-> OAuthCredentials -> f OAuthCredentials
oAuthCredentials_refreshToken = (OAuthCredentials -> Maybe Text)
-> (OAuthCredentials -> Maybe Text -> OAuthCredentials)
-> Lens OAuthCredentials OAuthCredentials (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OAuthCredentials' {Maybe Text
refreshToken :: Maybe Text
$sel:refreshToken:OAuthCredentials' :: OAuthCredentials -> Maybe Text
refreshToken} -> Maybe Text
refreshToken) (\s :: OAuthCredentials
s@OAuthCredentials' {} Maybe Text
a -> OAuthCredentials
s {$sel:refreshToken:OAuthCredentials' :: Maybe Text
refreshToken = Maybe Text
a} :: OAuthCredentials)

-- | The OAuth requirement needed to request security tokens from the
-- connector endpoint.
oAuthCredentials_oAuthRequest :: Lens.Lens' OAuthCredentials (Prelude.Maybe ConnectorOAuthRequest)
oAuthCredentials_oAuthRequest :: (Maybe ConnectorOAuthRequest -> f (Maybe ConnectorOAuthRequest))
-> OAuthCredentials -> f OAuthCredentials
oAuthCredentials_oAuthRequest = (OAuthCredentials -> Maybe ConnectorOAuthRequest)
-> (OAuthCredentials
    -> Maybe ConnectorOAuthRequest -> OAuthCredentials)
-> Lens
     OAuthCredentials
     OAuthCredentials
     (Maybe ConnectorOAuthRequest)
     (Maybe ConnectorOAuthRequest)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OAuthCredentials' {Maybe ConnectorOAuthRequest
oAuthRequest :: Maybe ConnectorOAuthRequest
$sel:oAuthRequest:OAuthCredentials' :: OAuthCredentials -> Maybe ConnectorOAuthRequest
oAuthRequest} -> Maybe ConnectorOAuthRequest
oAuthRequest) (\s :: OAuthCredentials
s@OAuthCredentials' {} Maybe ConnectorOAuthRequest
a -> OAuthCredentials
s {$sel:oAuthRequest:OAuthCredentials' :: Maybe ConnectorOAuthRequest
oAuthRequest = Maybe ConnectorOAuthRequest
a} :: OAuthCredentials)

-- | The identifier for the desired client.
oAuthCredentials_clientId :: Lens.Lens' OAuthCredentials Prelude.Text
oAuthCredentials_clientId :: (Text -> f Text) -> OAuthCredentials -> f OAuthCredentials
oAuthCredentials_clientId = (OAuthCredentials -> Text)
-> (OAuthCredentials -> Text -> OAuthCredentials)
-> Lens OAuthCredentials OAuthCredentials Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OAuthCredentials' {Text
clientId :: Text
$sel:clientId:OAuthCredentials' :: OAuthCredentials -> Text
clientId} -> Text
clientId) (\s :: OAuthCredentials
s@OAuthCredentials' {} Text
a -> OAuthCredentials
s {$sel:clientId:OAuthCredentials' :: Text
clientId = Text
a} :: OAuthCredentials)

-- | The client secret used by the OAuth client to authenticate to the
-- authorization server.
oAuthCredentials_clientSecret :: Lens.Lens' OAuthCredentials Prelude.Text
oAuthCredentials_clientSecret :: (Text -> f Text) -> OAuthCredentials -> f OAuthCredentials
oAuthCredentials_clientSecret = (OAuthCredentials -> Sensitive Text)
-> (OAuthCredentials -> Sensitive Text -> OAuthCredentials)
-> Lens
     OAuthCredentials OAuthCredentials (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OAuthCredentials' {Sensitive Text
clientSecret :: Sensitive Text
$sel:clientSecret:OAuthCredentials' :: OAuthCredentials -> Sensitive Text
clientSecret} -> Sensitive Text
clientSecret) (\s :: OAuthCredentials
s@OAuthCredentials' {} Sensitive Text
a -> OAuthCredentials
s {$sel:clientSecret:OAuthCredentials' :: Sensitive Text
clientSecret = Sensitive Text
a} :: OAuthCredentials) ((Sensitive Text -> f (Sensitive Text))
 -> OAuthCredentials -> f OAuthCredentials)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> OAuthCredentials
-> f OAuthCredentials
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Prelude.Hashable OAuthCredentials

instance Prelude.NFData OAuthCredentials

instance Core.ToJSON OAuthCredentials where
  toJSON :: OAuthCredentials -> Value
toJSON OAuthCredentials' {Maybe Text
Maybe (Sensitive Text)
Maybe ConnectorOAuthRequest
Text
Sensitive Text
clientSecret :: Sensitive Text
clientId :: Text
oAuthRequest :: Maybe ConnectorOAuthRequest
refreshToken :: Maybe Text
accessToken :: Maybe (Sensitive Text)
$sel:clientSecret:OAuthCredentials' :: OAuthCredentials -> Sensitive Text
$sel:clientId:OAuthCredentials' :: OAuthCredentials -> Text
$sel:oAuthRequest:OAuthCredentials' :: OAuthCredentials -> Maybe ConnectorOAuthRequest
$sel:refreshToken:OAuthCredentials' :: OAuthCredentials -> Maybe Text
$sel:accessToken:OAuthCredentials' :: OAuthCredentials -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"accessToken" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Sensitive Text -> Pair) -> Maybe (Sensitive Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive Text)
accessToken,
            (Text
"refreshToken" 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
refreshToken,
            (Text
"oAuthRequest" Text -> ConnectorOAuthRequest -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ConnectorOAuthRequest -> Pair)
-> Maybe ConnectorOAuthRequest -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ConnectorOAuthRequest
oAuthRequest,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"clientId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clientId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"clientSecret" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
clientSecret)
          ]
      )