kkpoon/elm-auth0/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Auth0

This library provides data types and helper functions for Auth0

Auth0 Basis

type alias Endpoint =
String

Auth0 Endpoint of Authentication API and Management API

e.g. https://your-auth0-app.auth0.com

type alias IdToken =
String

The idToken returns from Auth0 authenticated result, it is usually in JSON Web Token (JWT) format.

type alias UserID =
String

Represent the Auth0 unified user ID

type alias Auth0Config =
{ endpoint : Endpoint
, clientId : String
}

A config record of Auth0

User Profile

type alias Profile userMetaData appMetaData =
{ email : String
, email_verified : Bool
, family_name : String
, given_name : String
, global_client_id : Maybe String
, identities : List OAuth2Identity
, locale : Maybe String
, name : String
, nickname : String
, picture : String
, user_id : UserID
, user_metadata : Maybe userMetaData
, app_metadata : Maybe appMetaData
}

Auth0 unified user profile

The user_metatdata and app_metadata varies in different application. You should define your own user_metadata and app_metadata records.

type alias OAuth2Identity =
{ connection : String
, isSocial : Bool
, provider : String
, user_id : String
}

The OAuth2 identity of the unified user profile. This usually tell the social account or database account linked with the unified user profile.

profileDecoder : Decoder a -> Decoder b -> Decoder (Profile a b)

Auth0 unified user profile decoder

The user_metatdata and app_metadata varies in different application. You should define your own user_metadata and app_metadata decoders.

Helpers

auth0AuthorizeURL : Auth0Config -> String -> String -> List String -> Maybe String -> String

Create the URL to the login page

auth0AuthorizeURL :
    Auth0Config
    -> String -- responseType
    -> String -- redirectURL
    -> List String -- scopes
    -> Maybe String -- connection
    -> String

e.g.

auth0AuthorizeURL
    (Auth0Config "https://my-app.auth0.com" "aBcD1234")
    "token"
    "https://my-app/"
    [ "openid", "name", "email" ]
    (Just "google-oauth2")
getAuthedUserProfile : Endpoint -> IdToken -> Decoder profile -> Request profile

Get the Auth0 unified user profile which is represented by the IdToken

Endpoint
-> IdToken
-> UserID
-> Value
-> Decoder profile
-> Request profile

Update the user_metadata in the Auth0 unified user profile