Openmaize v0.10.0 Openmaize.Authenticate

Plug to authenticate users, using Json Web Tokens.

For more information about Json Web Tokens, see the documentation for the Openmaize.Token module.

This module also sets the current_user variable, which, if you are using Phoenix, can then be used in your templates. If no token is found, the current_user is set to nil.

There is one option:

  • storage - storage method for the token — the default is :cookie Set the storage method to nil if you want to use sessionStorage or localStorage

Examples

Call Authenticate without any options (the token will be stored in a cookie):

plug Openmaize.Authenticate

Call Authenticate and send the token in the response body:

plug Openmaize.Authenticate, storage: nil

Summary

Functions

This function checks the token, which is either in a cookie or the request headers and authenticates the user based on the information in the token

Callback implementation for c:Plug.init/1

Functions

call(conn, opts)

This function checks the token, which is either in a cookie or the request headers and authenticates the user based on the information in the token.

If the authentication is successful, a map, called :current_user, providing the user information is added to the assigns map in the Plug connection. If there is no token, or if the token is invalid, the :current_user is set to nil.

init(opts)

Callback implementation for c:Plug.init/1.