Configuration for form based authentication.
Tipically user credentials are exchanged for a JWT, to the PostgREST instance or to an external authentication provided.
This module provides configuration functions for defining what is the
authentication form POST url, how the credentials are to be encoded and how the
JWT is to be decoded.
FormAuth
configurations are to be used with
Config.formAuth.
See PostgREST documentation to get a better understanding of JWT and roles in PostgREST.
Json.Decode.Decoder Internal.FormAuth.FormAuth
Basic authentication configuration.
config : FormAuth
Create a authentication configuration.
authUrl : String -> FormAuth -> FormAuth
Set authentication request login url. Credentials are to be exchanged for a JWT via a post request.
authUrl "http://localhost:3000/rpc/login" config
Alternatively the host can be specified using flags, configuring using
authUrl
. Program flags take precedence.
Elm.Main.init
{ flags = { authUrl = "http://localhost:3000/rpc/login" }
}
encoder : (Dict String String -> Json.Encode.Value) -> FormAuth -> FormAuth
Override the credentials JSON encoder to be used when posting to the login url.
encoder
(\creds ->
Encode.object
[ ( "credentials"
, Encode.dict identity Encode.string creds
)
]
)
config
decoder : Json.Decode.Decoder String -> FormAuth -> FormAuth
Override the JSON decoder used to obtain the JWT from the login response.
decoder (Decode.at [ "auth", "jwt" ] Decode.string) config