{-# 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.GlobalSignOut
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Signs out users from all devices. It also invalidates all refresh tokens
-- that Amazon Cognito has issued to a user. A user can still use a hosted
-- UI cookie to retrieve new tokens for the duration of the 1-hour cookie
-- validity period.
module Amazonka.CognitoIdentityProvider.GlobalSignOut
  ( -- * Creating a Request
    GlobalSignOut (..),
    newGlobalSignOut,

    -- * Request Lenses
    globalSignOut_accessToken,

    -- * Destructuring the Response
    GlobalSignOutResponse (..),
    newGlobalSignOutResponse,

    -- * Response Lenses
    globalSignOutResponse_httpStatus,
  )
where

import Amazonka.CognitoIdentityProvider.Types
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Represents the request to sign out all devices.
--
-- /See:/ 'newGlobalSignOut' smart constructor.
data GlobalSignOut = GlobalSignOut'
  { -- | A valid access token that Amazon Cognito issued to the user who you want
    -- to sign out.
    GlobalSignOut -> Sensitive Text
accessToken :: Data.Sensitive Prelude.Text
  }
  deriving (GlobalSignOut -> GlobalSignOut -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GlobalSignOut -> GlobalSignOut -> Bool
$c/= :: GlobalSignOut -> GlobalSignOut -> Bool
== :: GlobalSignOut -> GlobalSignOut -> Bool
$c== :: GlobalSignOut -> GlobalSignOut -> Bool
Prelude.Eq, Int -> GlobalSignOut -> ShowS
[GlobalSignOut] -> ShowS
GlobalSignOut -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GlobalSignOut] -> ShowS
$cshowList :: [GlobalSignOut] -> ShowS
show :: GlobalSignOut -> String
$cshow :: GlobalSignOut -> String
showsPrec :: Int -> GlobalSignOut -> ShowS
$cshowsPrec :: Int -> GlobalSignOut -> ShowS
Prelude.Show, forall x. Rep GlobalSignOut x -> GlobalSignOut
forall x. GlobalSignOut -> Rep GlobalSignOut x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GlobalSignOut x -> GlobalSignOut
$cfrom :: forall x. GlobalSignOut -> Rep GlobalSignOut x
Prelude.Generic)

-- |
-- Create a value of 'GlobalSignOut' 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', 'globalSignOut_accessToken' - A valid access token that Amazon Cognito issued to the user who you want
-- to sign out.
newGlobalSignOut ::
  -- | 'accessToken'
  Prelude.Text ->
  GlobalSignOut
newGlobalSignOut :: Text -> GlobalSignOut
newGlobalSignOut Text
pAccessToken_ =
  GlobalSignOut'
    { $sel:accessToken:GlobalSignOut' :: Sensitive Text
accessToken =
        forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pAccessToken_
    }

-- | A valid access token that Amazon Cognito issued to the user who you want
-- to sign out.
globalSignOut_accessToken :: Lens.Lens' GlobalSignOut Prelude.Text
globalSignOut_accessToken :: Lens' GlobalSignOut Text
globalSignOut_accessToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GlobalSignOut' {Sensitive Text
accessToken :: Sensitive Text
$sel:accessToken:GlobalSignOut' :: GlobalSignOut -> Sensitive Text
accessToken} -> Sensitive Text
accessToken) (\s :: GlobalSignOut
s@GlobalSignOut' {} Sensitive Text
a -> GlobalSignOut
s {$sel:accessToken:GlobalSignOut' :: Sensitive Text
accessToken = Sensitive Text
a} :: GlobalSignOut) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Core.AWSRequest GlobalSignOut where
  type
    AWSResponse GlobalSignOut =
      GlobalSignOutResponse
  request :: (Service -> Service) -> GlobalSignOut -> Request GlobalSignOut
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GlobalSignOut
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GlobalSignOut)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> GlobalSignOutResponse
GlobalSignOutResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GlobalSignOut where
  hashWithSalt :: Int -> GlobalSignOut -> Int
hashWithSalt Int
_salt GlobalSignOut' {Sensitive Text
accessToken :: Sensitive Text
$sel:accessToken:GlobalSignOut' :: GlobalSignOut -> Sensitive Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
accessToken

instance Prelude.NFData GlobalSignOut where
  rnf :: GlobalSignOut -> ()
rnf GlobalSignOut' {Sensitive Text
accessToken :: Sensitive Text
$sel:accessToken:GlobalSignOut' :: GlobalSignOut -> Sensitive Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
accessToken

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

instance Data.ToJSON GlobalSignOut where
  toJSON :: GlobalSignOut -> Value
toJSON GlobalSignOut' {Sensitive Text
accessToken :: Sensitive Text
$sel:accessToken:GlobalSignOut' :: GlobalSignOut -> Sensitive Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"AccessToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
accessToken)]
      )

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

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

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

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

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

instance Prelude.NFData GlobalSignOutResponse where
  rnf :: GlobalSignOutResponse -> ()
rnf GlobalSignOutResponse' {Int
httpStatus :: Int
$sel:httpStatus:GlobalSignOutResponse' :: GlobalSignOutResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus