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:
OAuth.AuthorizationCode: The authorization code grant type is used to obtain both access tokens and refresh tokens via a redirection-based flow and is optimized for confidential clients 4.1.
OAuth.Implicit: The implicit grant type is used to obtain access tokens (it does not support the issuance of refresh tokens) and is optimized for public clients known to operate a particular redirection URI 4.2.
OAuth.Password: The resource owner password credentials grant type is suitable in cases where the resource owner has a trust relationship with the client, such as the device operating system or a highly privileged application 4.3
OAuth.ClientCredentials: The client can request an access token using only its client credentials (or other supported means of authentication) when the client is requesting access to the protected resources under its control, or those of another resource owner that have been previously arranged with the authorization server (the method of which is beyond the scope of this specification) 4.4.
In practice, you most probably want to use the OAuth.Implicit module which is the most commonly used.
Request configuration for an authorization (Authorization Code & Implicit flows)
Request configuration for an authentication (Authorization Code, Password & Client Credentials flows)
-- AuthorizationCode
let req = OAuth.AuthorizationCode
{ credentials =
{ clientId = "<my-client-id>"
, secret = ""
}
,
, code = "<authorization-code>"
, url = "<token-endpoint>"
, redirectUri = "<my-web-server>"
, scope = ["read:whatever"]
, state = "whatever"
}
-- ClientCredentials
let req = OAuth.ClientCredentials
{ credentials =
{ clientId = "<my-client-id>"
, secret = "<my-client-secret>"
}
, url = "<token-endpoint>"
, scope = ["read:whatever"]
, state = "whatever"
}
-- Password
let req = OAuth.Password
{ credentials = Just
{ clientId = "<my-client-id>"
, secret = "<my-client-secret>"
}
, password = "<user-password>"
, scope = ["read:whatever"]
, state = "whatever"
, url = "<token-endpoint>"
, username = "<user-username>"
}
-- Refresh
let req = OAuth.Refresh
{ credentials = Nothing
, scope = ["read:whatever"]
, token = OAuth.Bearer "abcdef1234567890"
, url = "<token-endpoint>"
}Describes a couple of client credentials used for Basic authentication
Describes the desired type of response to an authorization. Use Code to ask for an
authorization code and continue with the according flow. Use Token to do an implicit
authentication and directly retrieve a Token from the authorization.
Gets the String representation of a ResponseType.
The response obtained as a result of an authorization or authentication. OkCode can only be
encountered after an authorization.
Describes the type of access token to use.
Bearer: Utilized by simply including the access token string in the request rfc6750
Mac: Not yet supported.
Describes errors coming from attempting to parse a url after an OAuth redirection
Describes an OAuth error response 4.1.2.1
InvalidRequest: The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.
UnauthorizedClient: The client is not authorized to request an authorization code using this method.
AccessDenied: The resource owner or authorization server denied the request.
UnsupportedResponseType: The authorization server does not support obtaining an authorization code using this method.
InvalidScope: The requested scope is invalid, unknown, or malformed.
ServerError: The authorization server encountered an unexpected condition that prevented it from fulfilling the request. (This error code is needed because a 500 Internal Server Error HTTP status code cannot be returned to the client via an HTTP redirect.)
TemporarilyUnavailable: The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server. (This error code is needed because a 503 Service Unavailable HTTP status code cannot be returned to the client via an HTTP redirect.)
Unknown: The server returned an unknown error code.
Gets the String representation of a Token.
Gets the String representation of an Error.
Attempts to parse a String into an Error code. Will parse to Unknown when the string
isn't recognized.
A json decoder for response error carried by the Result Http.Error OAuth.Response result of
an http call.
Use a token to authenticate a request.