{-# LANGUAGE FlexibleContexts #-}
module Network.OAuth2.Experiment.Flows.TokenRequest where
import Data.Text.Encoding qualified as T
import Data.Text.Lazy qualified as TL
import Network.HTTP.Conduit
import Network.OAuth2 (
ClientAuthenticationMethod (..),
)
import Network.OAuth2.Experiment.Types (
ClientId (unClientId),
ClientSecret (unClientSecret),
)
addSecretToHeader :: ClientId -> ClientSecret -> Request -> Request
ClientId
cid ClientSecret
csecret =
ByteString -> ByteString -> Request -> Request
applyBasicAuth
(Text -> ByteString
T.encodeUtf8 (Text -> ByteString) -> Text -> ByteString
forall a b. (a -> b) -> a -> b
$ LazyText -> Text
TL.toStrict (LazyText -> Text) -> LazyText -> Text
forall a b. (a -> b) -> a -> b
$ ClientId -> LazyText
unClientId ClientId
cid)
(Text -> ByteString
T.encodeUtf8 (Text -> ByteString) -> Text -> ByteString
forall a b. (a -> b) -> a -> b
$ LazyText -> Text
TL.toStrict (LazyText -> Text) -> LazyText -> Text
forall a b. (a -> b) -> a -> b
$ ClientSecret -> LazyText
unClientSecret ClientSecret
csecret)
class HasClientAuthenticationMethod a where
getClientAuthenticationMethod :: a -> ClientAuthenticationMethod
:: a -> Request -> Request
addClientAuthToHeader a
_ = Request -> Request
forall a. a -> a
id
data NoNeedExchangeToken = NoNeedExchangeToken
class HasClientAuthenticationMethod a => HasTokenRequest a where
data TokenRequest a
type ExchangeTokenInfo a
mkTokenRequestParam :: a -> ExchangeTokenInfo a -> TokenRequest a