billstclair / elm-oauth-middleware / OAuthMiddleware.EncodeDecode

JSON Encoders and Decoders for the OAuthMiddleware module.

Types


type alias Authorization =
{ name : String
, authorizationUri : String
, tokenUri : String
, apiUri : String
, clientId : String
, redirectUri : String
, scopes : Dict String String 
}

Authorization information to send to the redirect (callback) server.

Usually stored in a JSON file, and read and decoded by OAuthMiddleware.getAuthorizations or OAuthMiddleware.getAuthorization.


type alias RedirectState =
{ clientId : String
, tokenUri : String
, redirectUri : String
, scope : List String
, redirectBackUri : String
, state : Maybe String 
}

The state sent to the redirectUri.

This is created by OAuthMiddleware.authorize from the passed TokenAuthorization.


type alias ResponseTokenError =
{ err : String
, state : Maybe String 
}

If an error occurs getting a token from the token server, it is encoded in a ResponseTokenError.

Encode/Decode state for passing over the wire.

encodeRedirectState : RedirectState -> String

Encode the redirectBackUri and user state for the authorization server.

decodeRedirectState : String -> Result String RedirectState

Decode the state encoded by encodeRedirectState.

encodeResponseToken : OAuthMiddleware.ResponseToken.ResponseToken -> String

Encode the ResponseToken that is received by the redirect server from its call to OAuth.AuthorizationCode.authenticate.

decodeResponseToken : String -> Result String OAuthMiddleware.ResponseToken.ResponseToken

Decode the ResponseToken that is sent back to the redirectUri from the redirect server.

encodeResponseTokenError : ResponseTokenError -> String

Encode the ResponseTokenError that may be sent back to the redirectUri from the redirect server.

decodeResponseTokenError : String -> Result String ResponseTokenError

Decode the ResponseTokenError that may be sent back to the redirectUri from the redirect server.

Encoders and Decoders

authorizationsDecoder : Json.Decode.Decoder (List Authorization)

Decode an Authorization list.

Usually used via OAuthMiddleware.getAuthorizations.

authorizationsEncoder : List Authorization -> Json.Encode.Value

Encode an Authorization list.

authorizationDecoder : Json.Decode.Decoder Authorization

Decode an Authorization.

Usually used via OAuthMiddleware.getAuthorization.

authorizationEncoder : Authorization -> Json.Encode.Value

Encode an Authorization.

redirectStateDecoder : Json.Decode.Decoder RedirectState

Decode the state sent to the authenticate server via OAuth.AuthorizationCode.authenticate and received by the redirect server.

redirectStateEncoder : RedirectState -> Json.Encode.Value

Encode the state sent to the authenticate server via OAuth.AuthorizationCode.authenticate and received by the redirect server.

responseTokenDecoder : Json.Decode.Decoder OAuthMiddleware.ResponseToken.ResponseToken

Decode the "response-token" query arg for the redirectBackUri.

Changes the default by swapping lenientScopeDecoder for scopeDecoder.

This isn't necessary on the client side, but is needed by the server for GitHub.

responseTokenEncoder : OAuthMiddleware.ResponseToken.ResponseToken -> Json.Encode.Value

Encode the "response-token" query arg for the redirectBackUri

responseTokenErrorDecoder : Json.Decode.Decoder ResponseTokenError

Decode a ResponseTokenError.

responseTokenErrorEncoder : ResponseTokenError -> Json.Encode.Value

Turn a ResponseTokenError into a Value.

nullableStringEncoder : Maybe String -> Json.Encode.Value

Simple encoder for a nullable string.