Haytni.RememberablePlugin (Haytni v0.6.3) View Source
This plugin makes artificialy last user's authentication by creating a cookie which stores a token for remembering the user.
This cookie is cleared when user's manually logout.
Fields:
- remember_token (string, nullable, unique, default:
NULL
): the token to sign in automatically (NULL
if the account doesn't use this function) - remember_created_at (datetime@utc, nullable, default:
NULL
): when the token was generated (alsoNULL
if the account doesn't use this function)
Configuration:
remember_for
(default:{2, :week}
): the period of validity of the token/which the user won't be asked for credentialsremember_salt
(default:""
): the salt to (de)cipher the token stored in the (signed) cookieremember_token_length
(default:16
): the length of the token (before being ciphered)remember_cookie_name
(default:"remember_token"
): the name of the cookie holding the token for automatic sign inremember_cookie_options
(default:[http_only: true, extra: "SameSite=Strict"]
): to set custom options of the cookie (options are: domain, max_age, path, http_only, secure and extra, see documentation of Plug.Conn.put_resp_cookie/4)stack Haytni.RememberablePlugin, remember_salt: "", remember_for: {2, :week}, remember_token_length: 16, remember_cookie_name: "remember_token", remember_cookie_options: [http_only: true, extra: "SameSite=Strict"]
Routes: none
Link to this section Summary
Functions
Sign remember_token then add it to conn response's cookies.
Callback implementation for Haytni.Plugin.invalid?/3
.
Callback implementation for Haytni.Plugin.on_email_change/4
.
Callback implementation for Haytni.Plugin.on_failed_authentication/5
.
Callback implementation for Haytni.Plugin.on_registration/3
.
Callback implementation for Haytni.Plugin.routes/2
.
Sign remember_token
Callback implementation for Haytni.Plugin.validate_create_registration/3
.
Callback implementation for Haytni.Plugin.validate_password/3
.
Callback implementation for Haytni.Plugin.validate_update_registration/3
.
Fetches the rememberme token from its signature.
Link to this section Functions
Specs
add_rememberme_cookie( conn :: Plug.Conn.t(), remember_token :: String.t(), config :: Haytni.RememberablePlugin.Config.t() ) :: Plug.Conn.t()
Sign remember_token then add it to conn response's cookies.
Returns the updated %Plug.Conn{}
with our rememberme cookie
Callback implementation for Haytni.Plugin.invalid?/3
.
Callback implementation for Haytni.Plugin.on_email_change/4
.
Callback implementation for Haytni.Plugin.on_failed_authentication/5
.
Callback implementation for Haytni.Plugin.on_registration/3
.
Callback implementation for Haytni.Plugin.routes/2
.
Specs
sign_token( conn :: Plug.Conn.t(), remember_token :: String.t(), config :: Haytni.RememberablePlugin.Config.t() ) :: String.t()
Sign remember_token
Callback implementation for Haytni.Plugin.validate_create_registration/3
.
Callback implementation for Haytni.Plugin.validate_password/3
.
Callback implementation for Haytni.Plugin.validate_update_registration/3
.
Specs
verify_token( conn :: Plug.Conn.t(), signed_token :: String.t() | nil, config :: Haytni.RememberablePlugin.Config.t() ) :: {:ok, String.t()} | {:error, :invalid | :missing}
Fetches the rememberme token from its signature.
Returns the token as {:ok, string}
but {:error, :invalid}
if signature is corrupted in any way or {:error, :missing}
if signed_token is nil