2017-09-07 22:38:31 +02:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
2016-02-17 20:12:47 +01:00
|
|
|
{-# LANGUAGE TypeSynonymInstances #-}
|
|
|
|
|
|
|
|
-- | Basic Authentication for clients
|
2019-02-18 18:08:13 +01:00
|
|
|
module Servant.Client.Core.BasicAuth (
|
|
|
|
basicAuthReq,
|
|
|
|
) where
|
2016-02-17 20:12:47 +01:00
|
|
|
|
2018-06-30 21:17:08 +02:00
|
|
|
import Data.ByteString.Base64
|
|
|
|
(encode)
|
|
|
|
import Data.Text.Encoding
|
|
|
|
(decodeUtf8)
|
|
|
|
import Servant.API.BasicAuth
|
|
|
|
(BasicAuthData (BasicAuthData))
|
2019-02-18 18:08:13 +01:00
|
|
|
import Servant.Client.Core.Request
|
2018-06-30 21:17:08 +02:00
|
|
|
(Request, addHeader)
|
2016-02-17 20:12:47 +01:00
|
|
|
|
|
|
|
-- | Authenticate a request using Basic Authentication
|
2017-09-06 23:13:05 +02:00
|
|
|
basicAuthReq :: BasicAuthData -> Request -> Request
|
2016-02-17 20:12:47 +01:00
|
|
|
basicAuthReq (BasicAuthData user pass) req =
|
|
|
|
let authText = decodeUtf8 ("Basic " <> encode (user <> ":" <> pass))
|
|
|
|
in addHeader "Authorization" authText req
|