hoauth2-0.5.0: hoauth2

Safe Haskell | None
Language | Haskell2010

Network.OAuth.OAuth2.Internal

Contents

- Data Types
- Types Synonym
- URLs
- UTILs

Description

A simple OAuth2 Haskell binding. (This is supposed to be independent with http client.)

Synopsis

- data OAuth2 = OAuth2 {
  - oauthClientId :: ByteString
  - oauthClientSecret :: ByteString
  - oauthOAuthorizeEndpoint :: ByteString
  - oauthAccessTokenEndpoint :: ByteString
  - oauthCallback :: Maybe ByteString
  }
- data AccessToken = AccessToken {
  - accessToken :: ByteString
  - refreshToken :: Maybe ByteString
  - expiresIn :: Maybe Int
  - tokenType :: Maybe ByteString
  }
- type OAuth2Result a = Either ByteString a
- type QueryParams = [(ByteString, ByteString)]
- type PostBody = [(ByteString, ByteString)]
- type URI = ByteString
- authorizationUrl :: OAuth2 -> URI
- accessTokenUrl :: OAuth2 -> ByteString -> (URI, PostBody)
- accessTokenUrl' :: OAuth2 -> ByteString -> Maybe ByteString -> (URI, PostBody)
- refreshAccessTokenUrl :: OAuth2 -> ByteString -> (URI, PostBody)
- appendQueryParam :: URI -> QueryParams -> URI
- appendAccessToken :: URI -> AccessToken -> URI
- accessTokenToParam :: AccessToken -> QueryParams
- transform' :: [(a, Maybe b)] -> [(a, b)]

# Data Types

data OAuth2 Source

Query Parameter Representation

Constructors

OAuth2 |

Fields

oauthClientId :: ByteString
oauthClientSecret :: ByteString
oauthOAuthorizeEndpoint :: ByteString
oauthAccessTokenEndpoint :: ByteString
oauthCallback :: Maybe ByteString

Instances

Eq OAuth2 Source |
Show OAuth2 Source |

data AccessToken Source

The gained Access Token. Use `Data.Aeson.decode` to decode string to `AccessToken`. The `refresheToken` is special at some case. e.g. https://developers.google.com/accounts/docs/OAuth2

Constructors

AccessToken |

Fields

accessToken :: ByteString
refreshToken :: Maybe ByteString
expiresIn :: Maybe Int
tokenType :: Maybe ByteString

Instances

Show AccessToken Source |
FromJSON AccessToken Source | Parse JSON data into {AccessToken}

# Types Synonym

type OAuth2Result a = Either ByteString a Source

Is either `Left` containing an error or `Right` containg a result

type QueryParams = [(ByteString, ByteString)] Source

type synonym of query parameters

type PostBody = [(ByteString, ByteString)] Source

type synonym of post body content

type URI = ByteString Source

type synonym of a URI

# URLs

authorizationUrl :: OAuth2 -> URI Source

Prepare the authorization URL. Redirect to this URL asking for user interactive authentication.

accessTokenUrl Source

Arguments

:: OAuth2 |
-> ByteString | access code gained via authorization URL
-> (URI, PostBody) | access token request URL plus the request body.

Prepare URL and the request body query for fetching access token.

accessTokenUrl' Source

Arguments

:: OAuth2 |
-> ByteString | access code gained via authorization URL
-> Maybe ByteString | Grant Type
-> (URI, PostBody) | access token request URL plus the request body.

refreshAccessTokenUrl Source

Arguments

:: OAuth2 |
-> ByteString | refresh token gained via authorization URL
-> (URI, PostBody) | refresh token request URL plus the request body.

Using a Refresh Token. obtain a new access token by sending a refresh token to the Authorization server.

# UTILs

appendQueryParam :: URI -> QueryParams -> URI Source

Append query parameters with `?`

appendAccessToken Source

Arguments

:: URI | Base URI
-> AccessToken | Authorized Access Token
-> URI | Combined Result

Append query parameters with `&`. appendQueryParam' :: URI -> QueryParams -> URI appendQueryParam' uri q = uri `append` "&" `append` renderSimpleQuery False q

For GET method API.

accessTokenToParam :: AccessToken -> QueryParams Source

Create QueryParams with given access token value.

accessTokenToParam :: BS.ByteString -> QueryParams accessTokenToParam token = [("access_token", token)]

transform' :: [(a, Maybe b)] -> [(a, b)] Source

lift value in the Maybe and abonda Nothing