solcates / solcates-elm-oauth2 / OAuth

Utility library to manage client-side OAuth 2.0 authentications

The library contains a main OAuth module exposing types used accross other modules. In practice, you'll only need tu use one of the additional modules:

In practice, you most probably want to use the OAuth.Implicit module which is the most commonly used.

Token


type Token

Describes the type of access token to use.

useToken : Token -> List Http.Header -> List Http.Header

Use a token to authenticate a request.

tokenToString : Token -> String

Get the String representation of a Token to be used in an 'Authorization' header

tokenFromString : String -> Maybe Token

Parse a token from an 'Authorization' header string.

  tokenFromString (tokenToString token) == Just token

ErrorCode


type ErrorCode
    = InvalidRequest
    | UnauthorizedClient
    | AccessDenied
    | UnsupportedResponseType
    | InvalidScope
    | ServerError
    | TemporarilyUnavailable
    | Custom String

Describes an OAuth error response 4.1.2.1

errorCodeToString : ErrorCode -> String

Get the String representation of an ErrorCode.

errorCodeFromString : String -> ErrorCode

Build a string back into an error code. Returns Custom _ when the string isn't recognized from the ones specified in the RFC

Decoders & Parsers Utils (advanced)


type alias TokenType =
String

Alias for readability


type alias TokenString =
String

Alias for readability

makeToken : Maybe TokenType -> Maybe TokenString -> Maybe Token

Create a token from two string representing a token type and an actual token value. This is intended to be used in Json decoders or Query parsers.

Returns Nothing when the token type is Nothing , different from Just "Bearer" or when there's no token at all.

makeRefreshToken : TokenType -> Maybe TokenString -> Maybe (Maybe Token)

See makeToken, with the subtle difference that a token value may or may not be there.

Returns Nothing when the token type isn't "Bearer".

Returns Just Nothing or Just (Just token) otherwise, depending on whether a token is present or not.