kkpoon / elm-auth0 / 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 : Basics.Bool
, created_at : Time.Posix
, family_name : Maybe String
, given_name : Maybe 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 : Basics.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 : Json.Decode.Decoder a -> Json.Decode.Decoder b -> Json.Decode.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 -> Json.Decode.Decoder String -> Platform.Cmd.Cmd Msg

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

updateUserMetaData : Endpoint -> IdToken -> UserID -> Json.Encode.Value -> Json.Decode.Decoder String -> Platform.Cmd.Cmd Msg

Update the user_metadata in the Auth0 unified user profile