hoauth2-1.8.7: Haskell OAuth2 authentication client

Safe Haskell | None
Language | Haskell2010

Network.OAuth.OAuth2.HttpClient

Contents

- Token management
- AUTH requests
- Utilities

Description

A simple http client to request OAuth2 tokens and several utils.

Synopsis

- fetchAccessToken :: Manager -> OAuth2 -> ExchangeToken -> IO (OAuth2Result Errors OAuth2Token)
- fetchAccessToken2 :: Manager -> OAuth2 -> ExchangeToken -> IO (OAuth2Result Errors OAuth2Token)
- fetchRefreshToken :: Manager -> OAuth2 -> RefreshToken -> IO (OAuth2Result Errors OAuth2Token)
- refreshAccessToken :: Manager -> OAuth2 -> RefreshToken -> IO (OAuth2Result Errors OAuth2Token)
- doJSONPostRequest :: FromJSON err => FromJSON a => Manager -> OAuth2 -> URI -> PostBody -> IO (OAuth2Result err a)
- doFlexiblePostRequest :: FromJSON err => FromJSON a => Manager -> OAuth2 -> URI -> PostBody -> IO (OAuth2Result err a)
- doSimplePostRequest :: FromJSON err => Manager -> OAuth2 -> URI -> PostBody -> IO (OAuth2Result err ByteString)
- authGetJSON :: FromJSON err => FromJSON a => Manager -> AccessToken -> URI -> IO (OAuth2Result err a)
- authGetBS :: FromJSON err => Manager -> AccessToken -> URI -> IO (OAuth2Result err ByteString)
- authGetBS2 :: FromJSON err => Manager -> AccessToken -> URI -> IO (OAuth2Result err ByteString)
- authPostJSON :: FromJSON err => FromJSON a => Manager -> AccessToken -> URI -> PostBody -> IO (OAuth2Result err a)
- authPostBS :: FromJSON err => Manager -> AccessToken -> URI -> PostBody -> IO (OAuth2Result err ByteString)
- authPostBS2 :: FromJSON err => Manager -> AccessToken -> URI -> PostBody -> IO (OAuth2Result err ByteString)
- authPostBS3 :: FromJSON err => Manager -> AccessToken -> URI -> IO (OAuth2Result err ByteString)
- authRequest :: FromJSON err => Request -> (Request -> Request) -> Manager -> IO (OAuth2Result err ByteString)
- handleResponse :: FromJSON err => Response ByteString -> OAuth2Result err ByteString
- parseResponseJSON :: FromJSON err => FromJSON a => OAuth2Result err ByteString -> OAuth2Result err a
- parseResponseFlexible :: FromJSON err => FromJSON a => OAuth2Result err ByteString -> OAuth2Result err a
- updateRequestHeaders :: Maybe AccessToken -> Request -> Request
- setMethod :: StdMethod -> Request -> Request

# Token management

fetchAccessToken Source #

Arguments

:: Manager | HTTP connection manager
-> OAuth2 | OAuth Data
-> ExchangeToken | OAuth 2 Tokens
-> IO (OAuth2Result Errors OAuth2Token) | Access Token

Request OAuth2 Token method: POST authenticate in header

fetchAccessToken2 Source #

Arguments

:: Manager | HTTP connection manager
-> OAuth2 | OAuth Data
-> ExchangeToken | OAuth 2 Tokens
-> IO (OAuth2Result Errors OAuth2Token) | Access Token

Request OAuth2 Token method: POST authenticate in both header and body

fetchRefreshToken Source #

Arguments

:: Manager | HTTP connection manager.
-> OAuth2 | OAuth context
-> RefreshToken | refresh token gained after authorization
-> IO (OAuth2Result Errors OAuth2Token) |

Deprecated: Use refreshAccessToken since this method will be removed in future release

refreshAccessToken Source #

Arguments

:: Manager | HTTP connection manager.
-> OAuth2 | OAuth context
-> RefreshToken | refresh token gained after authorization
-> IO (OAuth2Result Errors OAuth2Token) |

Request a new AccessToken with the Refresh Token.

doJSONPostRequest Source #

Arguments

:: FromJSON err |
=> FromJSON a |
=> Manager | HTTP connection manager.
-> OAuth2 | OAuth options
-> URI | The URL
-> PostBody | request body
-> IO (OAuth2Result err a) | Response as JSON

Conduct post request and return response as JSON.

doFlexiblePostRequest Source #

Arguments

:: FromJSON err |
=> FromJSON a |
=> Manager | HTTP connection manager.
-> OAuth2 | OAuth options
-> URI | The URL
-> PostBody | request body
-> IO (OAuth2Result err a) | Response as ByteString

Deprecated: Use doJSONPostRequest since this function would be removed in future release.

Conduct post request and return response as JSON or Query String.

doSimplePostRequest Source #

Arguments

:: FromJSON err |
=> Manager | HTTP connection manager.
-> OAuth2 | OAuth options
-> URI | URL
-> PostBody | Request body.
-> IO (OAuth2Result err ByteString) | Response as ByteString

Conduct post request.

# AUTH requests

authGetJSON Source #

Arguments

:: FromJSON err |
=> FromJSON a |
=> Manager | HTTP connection manager.
-> AccessToken |
-> URI |
-> IO (OAuth2Result err a) | Response as JSON

Conduct an authorized GET request and return response as JSON.

authGetBS Source #

Arguments

:: FromJSON err |
=> Manager | HTTP connection manager.
-> AccessToken |
-> URI |
-> IO (OAuth2Result err ByteString) | Response as ByteString

Conduct an authorized GET request.

authGetBS2 Source #

Arguments

:: FromJSON err |
=> Manager | HTTP connection manager.
-> AccessToken |
-> URI |
-> IO (OAuth2Result err ByteString) | Response as ByteString

same to `authGetBS` but set access token to query parameter rather than header

authPostJSON Source #

Arguments

:: FromJSON err |
=> FromJSON a |
=> Manager | HTTP connection manager.
-> AccessToken |
-> URI |
-> PostBody |
-> IO (OAuth2Result err a) | Response as JSON

Conduct POST request and return response as JSON.

authPostBS Source #

Arguments

:: FromJSON err |
=> Manager | HTTP connection manager.
-> AccessToken |
-> URI |
-> PostBody |
-> IO (OAuth2Result err ByteString) | Response as ByteString

Conduct POST request.

authPostBS2 Source #

Arguments

:: FromJSON err |
=> Manager | HTTP connection manager.
-> AccessToken |
-> URI |
-> PostBody |
-> IO (OAuth2Result err ByteString) | Response as ByteString

Conduct POST request with access token in the request body rather header

authPostBS3 Source #

Arguments

:: FromJSON err |
=> Manager | HTTP connection manager.
-> AccessToken |
-> URI |
-> IO (OAuth2Result err ByteString) | Response as ByteString

Conduct POST request with access token in the header and null in body

authRequest Source #

Arguments

:: FromJSON err |
=> Request | Request to perform
-> (Request -> Request) | Modify request before sending
-> Manager | HTTP connection manager.
-> IO (OAuth2Result err ByteString) |

Send an HTTP request including the Authorization header with the specified access token.

# Utilities

handleResponse :: FromJSON err => Response ByteString -> OAuth2Result err ByteString Source #

Parses a `Response` to to `OAuth2Result`

parseResponseJSON :: FromJSON err => FromJSON a => OAuth2Result err ByteString -> OAuth2Result err a Source #

Parses a `OAuth2Result BSL.ByteString` into `FromJSON a => a`

parseResponseFlexible :: FromJSON err => FromJSON a => OAuth2Result err ByteString -> OAuth2Result err a Source #

Try `parseResponseJSON`, if failed then parses the `OAuth2Result BSL.ByteString` that contains not JSON but a Query String.

updateRequestHeaders :: Maybe AccessToken -> Request -> Request Source #

Set several header values: + userAgennt : `hoauth2` + accept : `application/json` + authorization : `Bearer` `xxxxx` if `AccessToken` provided.

setMethod :: StdMethod -> Request -> Request Source #

Set the HTTP method to use.