truqu/elm-oauth2/2.2.0

NOTE: this package is not compatible with Elm 0.19.1

OAuth.Decode

This module exposes decoders and helpers to fine tune some requests when necessary.

This might come in handy for provider that doesn't exactly implement the OAuth 2.0 RFC (like the API v3 of GitHub). With these utilities, one should hopefully be able to adjust requests made to the Authorization Server and cope with implementation quirks.

Type Utilities

type alias RequestParts a =
{ method : String
, headers : List Header
, url : String
, body : Body
, expect : Expect a
, timeout : Maybe Time
, withCredentials : Bool
}

Parts required to build a request. This record is given to Http.request in order to create a new request and may be adjusted at will.

type alias AdjustRequest a =
RequestParts a -> RequestParts a

Alias for the behavior passed to some function in order to adjust Http Request before they get sent

For instance,

adjustRequest : AdjustRequest ResponseToken
adjustRequest req =
    { req | headers = [ Http.header "Accept" ("application/json") ] :: req.headers }

Json Decoders

responseDecoder : Decoder ResponseToken

Json decoder for a response. You may provide a custom response decoder using other decoders from this module, or some of your own craft.

For instance,

myScopeDecoder : Json.Decoder (Maybe (List String))
myScopeDecoder =
    Json.maybe <|
        Json.oneOf
            [ Json.field "scope" (Json.map (String.split ",") Json.string) ]


myResponseDecoder : Json.Decoder ResponseToken
myResponseDecoder =
    Json.map5 makeResponseToken
        accessTokenDecoder
        expiresInDecoder
        refreshTokenDecoder
        myScopeDecoder
        stateDecoder
expiresInDecoder : Decoder (Maybe Int)

Json decoder for an expire timestamp

scopeDecoder : Decoder (Maybe (List String))

Json decoder for a scope

lenientScopeDecoder : Decoder (Maybe (List String))

Json decoder for a scope, allowing comma- or space-separated scopes

stateDecoder : Decoder (Maybe String)

Json decoder for a state

accessTokenDecoder : Decoder Token

Json decoder for an access token

refreshTokenDecoder : Decoder (Maybe Token)

Json decoder for a refresh token

Constructors

makeToken : Maybe String -> String -> Maybe Token

Create a Token from a value and token type. Note that only bearer token are supported

Token
-> Maybe Int
-> Maybe Token
-> Maybe (List String)
-> Maybe String
-> ResponseToken

Create a ResponseToken record from various parameters