{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CognitoIdentityProvider.RevokeToken
-- 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)
--
-- Revokes all of the access tokens generated by the specified refresh
-- token. After the token is revoked, you can not use the revoked token to
-- access Cognito authenticated APIs.
module Amazonka.CognitoIdentityProvider.RevokeToken
  ( -- * Creating a Request
    RevokeToken (..),
    newRevokeToken,

    -- * Request Lenses
    revokeToken_clientSecret,
    revokeToken_token,
    revokeToken_clientId,

    -- * Destructuring the Response
    RevokeTokenResponse (..),
    newRevokeTokenResponse,

    -- * Response Lenses
    revokeTokenResponse_httpStatus,
  )
where

import Amazonka.CognitoIdentityProvider.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newRevokeToken' smart constructor.
data RevokeToken = RevokeToken'
  { -- | The secret for the client ID. This is required only if the client ID has
    -- a secret.
    RevokeToken -> Maybe (Sensitive Text)
clientSecret :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | The token that you want to revoke.
    RevokeToken -> Sensitive Text
token :: Core.Sensitive Prelude.Text,
    -- | The client ID for the token that you want to revoke.
    RevokeToken -> Sensitive Text
clientId :: Core.Sensitive Prelude.Text
  }
  deriving (RevokeToken -> RevokeToken -> Bool
(RevokeToken -> RevokeToken -> Bool)
-> (RevokeToken -> RevokeToken -> Bool) -> Eq RevokeToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RevokeToken -> RevokeToken -> Bool
$c/= :: RevokeToken -> RevokeToken -> Bool
== :: RevokeToken -> RevokeToken -> Bool
$c== :: RevokeToken -> RevokeToken -> Bool
Prelude.Eq, Int -> RevokeToken -> ShowS
[RevokeToken] -> ShowS
RevokeToken -> String
(Int -> RevokeToken -> ShowS)
-> (RevokeToken -> String)
-> ([RevokeToken] -> ShowS)
-> Show RevokeToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RevokeToken] -> ShowS
$cshowList :: [RevokeToken] -> ShowS
show :: RevokeToken -> String
$cshow :: RevokeToken -> String
showsPrec :: Int -> RevokeToken -> ShowS
$cshowsPrec :: Int -> RevokeToken -> ShowS
Prelude.Show, (forall x. RevokeToken -> Rep RevokeToken x)
-> (forall x. Rep RevokeToken x -> RevokeToken)
-> Generic RevokeToken
forall x. Rep RevokeToken x -> RevokeToken
forall x. RevokeToken -> Rep RevokeToken x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RevokeToken x -> RevokeToken
$cfrom :: forall x. RevokeToken -> Rep RevokeToken x
Prelude.Generic)

-- |
-- Create a value of 'RevokeToken' 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:
--
-- 'clientSecret', 'revokeToken_clientSecret' - The secret for the client ID. This is required only if the client ID has
-- a secret.
--
-- 'token', 'revokeToken_token' - The token that you want to revoke.
--
-- 'clientId', 'revokeToken_clientId' - The client ID for the token that you want to revoke.
newRevokeToken ::
  -- | 'token'
  Prelude.Text ->
  -- | 'clientId'
  Prelude.Text ->
  RevokeToken
newRevokeToken :: Text -> Text -> RevokeToken
newRevokeToken Text
pToken_ Text
pClientId_ =
  RevokeToken' :: Maybe (Sensitive Text)
-> Sensitive Text -> Sensitive Text -> RevokeToken
RevokeToken'
    { $sel:clientSecret:RevokeToken' :: Maybe (Sensitive Text)
clientSecret = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:token:RevokeToken' :: Sensitive Text
token = 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
pToken_,
      $sel:clientId:RevokeToken' :: Sensitive Text
clientId = 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
pClientId_
    }

-- | The secret for the client ID. This is required only if the client ID has
-- a secret.
revokeToken_clientSecret :: Lens.Lens' RevokeToken (Prelude.Maybe Prelude.Text)
revokeToken_clientSecret :: (Maybe Text -> f (Maybe Text)) -> RevokeToken -> f RevokeToken
revokeToken_clientSecret = (RevokeToken -> Maybe (Sensitive Text))
-> (RevokeToken -> Maybe (Sensitive Text) -> RevokeToken)
-> Lens
     RevokeToken
     RevokeToken
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RevokeToken' {Maybe (Sensitive Text)
clientSecret :: Maybe (Sensitive Text)
$sel:clientSecret:RevokeToken' :: RevokeToken -> Maybe (Sensitive Text)
clientSecret} -> Maybe (Sensitive Text)
clientSecret) (\s :: RevokeToken
s@RevokeToken' {} Maybe (Sensitive Text)
a -> RevokeToken
s {$sel:clientSecret:RevokeToken' :: Maybe (Sensitive Text)
clientSecret = Maybe (Sensitive Text)
a} :: RevokeToken) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> RevokeToken -> f RevokeToken)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> RevokeToken
-> f RevokeToken
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 token that you want to revoke.
revokeToken_token :: Lens.Lens' RevokeToken Prelude.Text
revokeToken_token :: (Text -> f Text) -> RevokeToken -> f RevokeToken
revokeToken_token = (RevokeToken -> Sensitive Text)
-> (RevokeToken -> Sensitive Text -> RevokeToken)
-> Lens RevokeToken RevokeToken (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RevokeToken' {Sensitive Text
token :: Sensitive Text
$sel:token:RevokeToken' :: RevokeToken -> Sensitive Text
token} -> Sensitive Text
token) (\s :: RevokeToken
s@RevokeToken' {} Sensitive Text
a -> RevokeToken
s {$sel:token:RevokeToken' :: Sensitive Text
token = Sensitive Text
a} :: RevokeToken) ((Sensitive Text -> f (Sensitive Text))
 -> RevokeToken -> f RevokeToken)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> RevokeToken
-> f RevokeToken
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

-- | The client ID for the token that you want to revoke.
revokeToken_clientId :: Lens.Lens' RevokeToken Prelude.Text
revokeToken_clientId :: (Text -> f Text) -> RevokeToken -> f RevokeToken
revokeToken_clientId = (RevokeToken -> Sensitive Text)
-> (RevokeToken -> Sensitive Text -> RevokeToken)
-> Lens RevokeToken RevokeToken (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RevokeToken' {Sensitive Text
clientId :: Sensitive Text
$sel:clientId:RevokeToken' :: RevokeToken -> Sensitive Text
clientId} -> Sensitive Text
clientId) (\s :: RevokeToken
s@RevokeToken' {} Sensitive Text
a -> RevokeToken
s {$sel:clientId:RevokeToken' :: Sensitive Text
clientId = Sensitive Text
a} :: RevokeToken) ((Sensitive Text -> f (Sensitive Text))
 -> RevokeToken -> f RevokeToken)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> RevokeToken
-> f RevokeToken
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 Core.AWSRequest RevokeToken where
  type AWSResponse RevokeToken = RevokeTokenResponse
  request :: RevokeToken -> Request RevokeToken
request = Service -> RevokeToken -> Request RevokeToken
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RevokeToken
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RevokeToken)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse RevokeToken))
-> Logger
-> Service
-> Proxy RevokeToken
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RevokeToken)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> RevokeTokenResponse
RevokeTokenResponse'
            (Int -> RevokeTokenResponse)
-> Either String Int -> Either String RevokeTokenResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable RevokeToken

instance Prelude.NFData RevokeToken

instance Core.ToHeaders RevokeToken where
  toHeaders :: RevokeToken -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RevokeToken -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSCognitoIdentityProviderService.RevokeToken" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON RevokeToken where
  toJSON :: RevokeToken -> Value
toJSON RevokeToken' {Maybe (Sensitive Text)
Sensitive Text
clientId :: Sensitive Text
token :: Sensitive Text
clientSecret :: Maybe (Sensitive Text)
$sel:clientId:RevokeToken' :: RevokeToken -> Sensitive Text
$sel:token:RevokeToken' :: RevokeToken -> Sensitive Text
$sel:clientSecret:RevokeToken' :: RevokeToken -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ClientSecret" 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)
clientSecret,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Token" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
token),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ClientId" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
clientId)
          ]
      )

instance Core.ToPath RevokeToken where
  toPath :: RevokeToken -> ByteString
toPath = ByteString -> RevokeToken -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery RevokeToken where
  toQuery :: RevokeToken -> QueryString
toQuery = QueryString -> RevokeToken -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newRevokeTokenResponse' smart constructor.
data RevokeTokenResponse = RevokeTokenResponse'
  { -- | The response's http status code.
    RevokeTokenResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RevokeTokenResponse -> RevokeTokenResponse -> Bool
(RevokeTokenResponse -> RevokeTokenResponse -> Bool)
-> (RevokeTokenResponse -> RevokeTokenResponse -> Bool)
-> Eq RevokeTokenResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RevokeTokenResponse -> RevokeTokenResponse -> Bool
$c/= :: RevokeTokenResponse -> RevokeTokenResponse -> Bool
== :: RevokeTokenResponse -> RevokeTokenResponse -> Bool
$c== :: RevokeTokenResponse -> RevokeTokenResponse -> Bool
Prelude.Eq, ReadPrec [RevokeTokenResponse]
ReadPrec RevokeTokenResponse
Int -> ReadS RevokeTokenResponse
ReadS [RevokeTokenResponse]
(Int -> ReadS RevokeTokenResponse)
-> ReadS [RevokeTokenResponse]
-> ReadPrec RevokeTokenResponse
-> ReadPrec [RevokeTokenResponse]
-> Read RevokeTokenResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RevokeTokenResponse]
$creadListPrec :: ReadPrec [RevokeTokenResponse]
readPrec :: ReadPrec RevokeTokenResponse
$creadPrec :: ReadPrec RevokeTokenResponse
readList :: ReadS [RevokeTokenResponse]
$creadList :: ReadS [RevokeTokenResponse]
readsPrec :: Int -> ReadS RevokeTokenResponse
$creadsPrec :: Int -> ReadS RevokeTokenResponse
Prelude.Read, Int -> RevokeTokenResponse -> ShowS
[RevokeTokenResponse] -> ShowS
RevokeTokenResponse -> String
(Int -> RevokeTokenResponse -> ShowS)
-> (RevokeTokenResponse -> String)
-> ([RevokeTokenResponse] -> ShowS)
-> Show RevokeTokenResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RevokeTokenResponse] -> ShowS
$cshowList :: [RevokeTokenResponse] -> ShowS
show :: RevokeTokenResponse -> String
$cshow :: RevokeTokenResponse -> String
showsPrec :: Int -> RevokeTokenResponse -> ShowS
$cshowsPrec :: Int -> RevokeTokenResponse -> ShowS
Prelude.Show, (forall x. RevokeTokenResponse -> Rep RevokeTokenResponse x)
-> (forall x. Rep RevokeTokenResponse x -> RevokeTokenResponse)
-> Generic RevokeTokenResponse
forall x. Rep RevokeTokenResponse x -> RevokeTokenResponse
forall x. RevokeTokenResponse -> Rep RevokeTokenResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RevokeTokenResponse x -> RevokeTokenResponse
$cfrom :: forall x. RevokeTokenResponse -> Rep RevokeTokenResponse x
Prelude.Generic)

-- |
-- Create a value of 'RevokeTokenResponse' 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:
--
-- 'httpStatus', 'revokeTokenResponse_httpStatus' - The response's http status code.
newRevokeTokenResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RevokeTokenResponse
newRevokeTokenResponse :: Int -> RevokeTokenResponse
newRevokeTokenResponse Int
pHttpStatus_ =
  RevokeTokenResponse' :: Int -> RevokeTokenResponse
RevokeTokenResponse' {$sel:httpStatus:RevokeTokenResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
revokeTokenResponse_httpStatus :: Lens.Lens' RevokeTokenResponse Prelude.Int
revokeTokenResponse_httpStatus :: (Int -> f Int) -> RevokeTokenResponse -> f RevokeTokenResponse
revokeTokenResponse_httpStatus = (RevokeTokenResponse -> Int)
-> (RevokeTokenResponse -> Int -> RevokeTokenResponse)
-> Lens RevokeTokenResponse RevokeTokenResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RevokeTokenResponse' {Int
httpStatus :: Int
$sel:httpStatus:RevokeTokenResponse' :: RevokeTokenResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: RevokeTokenResponse
s@RevokeTokenResponse' {} Int
a -> RevokeTokenResponse
s {$sel:httpStatus:RevokeTokenResponse' :: Int
httpStatus = Int
a} :: RevokeTokenResponse)

instance Prelude.NFData RevokeTokenResponse