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

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

-- | The OAuth properties required for OAuth type authentication.
--
-- /See:/ 'newOAuthProperties' smart constructor.
data OAuthProperties = OAuthProperties'
  { -- | The token url required to fetch access\/refresh tokens using
    -- authorization code and also to refresh expired access token using
    -- refresh token.
    OAuthProperties -> Text
tokenUrl :: Prelude.Text,
    -- | The authorization code url required to redirect to SAP Login Page to
    -- fetch authorization code for OAuth type authentication.
    OAuthProperties -> Text
authCodeUrl :: Prelude.Text,
    -- | The OAuth scopes required for OAuth type authentication.
    OAuthProperties -> [Text]
oAuthScopes :: [Prelude.Text]
  }
  deriving (OAuthProperties -> OAuthProperties -> Bool
(OAuthProperties -> OAuthProperties -> Bool)
-> (OAuthProperties -> OAuthProperties -> Bool)
-> Eq OAuthProperties
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OAuthProperties -> OAuthProperties -> Bool
$c/= :: OAuthProperties -> OAuthProperties -> Bool
== :: OAuthProperties -> OAuthProperties -> Bool
$c== :: OAuthProperties -> OAuthProperties -> Bool
Prelude.Eq, ReadPrec [OAuthProperties]
ReadPrec OAuthProperties
Int -> ReadS OAuthProperties
ReadS [OAuthProperties]
(Int -> ReadS OAuthProperties)
-> ReadS [OAuthProperties]
-> ReadPrec OAuthProperties
-> ReadPrec [OAuthProperties]
-> Read OAuthProperties
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OAuthProperties]
$creadListPrec :: ReadPrec [OAuthProperties]
readPrec :: ReadPrec OAuthProperties
$creadPrec :: ReadPrec OAuthProperties
readList :: ReadS [OAuthProperties]
$creadList :: ReadS [OAuthProperties]
readsPrec :: Int -> ReadS OAuthProperties
$creadsPrec :: Int -> ReadS OAuthProperties
Prelude.Read, Int -> OAuthProperties -> ShowS
[OAuthProperties] -> ShowS
OAuthProperties -> String
(Int -> OAuthProperties -> ShowS)
-> (OAuthProperties -> String)
-> ([OAuthProperties] -> ShowS)
-> Show OAuthProperties
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OAuthProperties] -> ShowS
$cshowList :: [OAuthProperties] -> ShowS
show :: OAuthProperties -> String
$cshow :: OAuthProperties -> String
showsPrec :: Int -> OAuthProperties -> ShowS
$cshowsPrec :: Int -> OAuthProperties -> ShowS
Prelude.Show, (forall x. OAuthProperties -> Rep OAuthProperties x)
-> (forall x. Rep OAuthProperties x -> OAuthProperties)
-> Generic OAuthProperties
forall x. Rep OAuthProperties x -> OAuthProperties
forall x. OAuthProperties -> Rep OAuthProperties x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OAuthProperties x -> OAuthProperties
$cfrom :: forall x. OAuthProperties -> Rep OAuthProperties x
Prelude.Generic)

-- |
-- Create a value of 'OAuthProperties' 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:
--
-- 'tokenUrl', 'oAuthProperties_tokenUrl' - The token url required to fetch access\/refresh tokens using
-- authorization code and also to refresh expired access token using
-- refresh token.
--
-- 'authCodeUrl', 'oAuthProperties_authCodeUrl' - The authorization code url required to redirect to SAP Login Page to
-- fetch authorization code for OAuth type authentication.
--
-- 'oAuthScopes', 'oAuthProperties_oAuthScopes' - The OAuth scopes required for OAuth type authentication.
newOAuthProperties ::
  -- | 'tokenUrl'
  Prelude.Text ->
  -- | 'authCodeUrl'
  Prelude.Text ->
  OAuthProperties
newOAuthProperties :: Text -> Text -> OAuthProperties
newOAuthProperties Text
pTokenUrl_ Text
pAuthCodeUrl_ =
  OAuthProperties' :: Text -> Text -> [Text] -> OAuthProperties
OAuthProperties'
    { $sel:tokenUrl:OAuthProperties' :: Text
tokenUrl = Text
pTokenUrl_,
      $sel:authCodeUrl:OAuthProperties' :: Text
authCodeUrl = Text
pAuthCodeUrl_,
      $sel:oAuthScopes:OAuthProperties' :: [Text]
oAuthScopes = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The token url required to fetch access\/refresh tokens using
-- authorization code and also to refresh expired access token using
-- refresh token.
oAuthProperties_tokenUrl :: Lens.Lens' OAuthProperties Prelude.Text
oAuthProperties_tokenUrl :: (Text -> f Text) -> OAuthProperties -> f OAuthProperties
oAuthProperties_tokenUrl = (OAuthProperties -> Text)
-> (OAuthProperties -> Text -> OAuthProperties)
-> Lens OAuthProperties OAuthProperties Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OAuthProperties' {Text
tokenUrl :: Text
$sel:tokenUrl:OAuthProperties' :: OAuthProperties -> Text
tokenUrl} -> Text
tokenUrl) (\s :: OAuthProperties
s@OAuthProperties' {} Text
a -> OAuthProperties
s {$sel:tokenUrl:OAuthProperties' :: Text
tokenUrl = Text
a} :: OAuthProperties)

-- | The authorization code url required to redirect to SAP Login Page to
-- fetch authorization code for OAuth type authentication.
oAuthProperties_authCodeUrl :: Lens.Lens' OAuthProperties Prelude.Text
oAuthProperties_authCodeUrl :: (Text -> f Text) -> OAuthProperties -> f OAuthProperties
oAuthProperties_authCodeUrl = (OAuthProperties -> Text)
-> (OAuthProperties -> Text -> OAuthProperties)
-> Lens OAuthProperties OAuthProperties Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OAuthProperties' {Text
authCodeUrl :: Text
$sel:authCodeUrl:OAuthProperties' :: OAuthProperties -> Text
authCodeUrl} -> Text
authCodeUrl) (\s :: OAuthProperties
s@OAuthProperties' {} Text
a -> OAuthProperties
s {$sel:authCodeUrl:OAuthProperties' :: Text
authCodeUrl = Text
a} :: OAuthProperties)

-- | The OAuth scopes required for OAuth type authentication.
oAuthProperties_oAuthScopes :: Lens.Lens' OAuthProperties [Prelude.Text]
oAuthProperties_oAuthScopes :: ([Text] -> f [Text]) -> OAuthProperties -> f OAuthProperties
oAuthProperties_oAuthScopes = (OAuthProperties -> [Text])
-> (OAuthProperties -> [Text] -> OAuthProperties)
-> Lens OAuthProperties OAuthProperties [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OAuthProperties' {[Text]
oAuthScopes :: [Text]
$sel:oAuthScopes:OAuthProperties' :: OAuthProperties -> [Text]
oAuthScopes} -> [Text]
oAuthScopes) (\s :: OAuthProperties
s@OAuthProperties' {} [Text]
a -> OAuthProperties
s {$sel:oAuthScopes:OAuthProperties' :: [Text]
oAuthScopes = [Text]
a} :: OAuthProperties) (([Text] -> f [Text]) -> OAuthProperties -> f OAuthProperties)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> OAuthProperties
-> f OAuthProperties
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable OAuthProperties

instance Prelude.NFData OAuthProperties

instance Core.ToJSON OAuthProperties where
  toJSON :: OAuthProperties -> Value
toJSON OAuthProperties' {[Text]
Text
oAuthScopes :: [Text]
authCodeUrl :: Text
tokenUrl :: Text
$sel:oAuthScopes:OAuthProperties' :: OAuthProperties -> [Text]
$sel:authCodeUrl:OAuthProperties' :: OAuthProperties -> Text
$sel:tokenUrl:OAuthProperties' :: OAuthProperties -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"tokenUrl" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
tokenUrl),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"authCodeUrl" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
authCodeUrl),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"oAuthScopes" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
oAuthScopes)
          ]
      )