AuthPlug (auth_plug v1.3.4)

AuthPlug handles all our auth needs in just a handful of lines of code. Please see README.md for setup instructions.

Link to this section Summary

Functions

call/2 is invoked to handle each HTTP request which auth_plug protects. If the conn contains a valid JWT in Authentication Headers, jwt query parameter or Phoenix Session, then continue to the protected route, else redirect to the auth_url with the referer set as the continuation URL.

init/1 initialises the options passed in and makes them available in the lifecycle of the call/2 invocation (below). We pass in the auth_url key/value with the URL of the Auth service to redirect to if session is invalid/expired.

logout/1 does exactly what you expect; logs the person out of your app. recieves a conn (Plug.Conn) and unsets the session. This is super-useful in testing as we can easily reset a session.

Link to this section Functions

Link to this function

call(conn, options)

call/2 is invoked to handle each HTTP request which auth_plug protects. If the conn contains a valid JWT in Authentication Headers, jwt query parameter or Phoenix Session, then continue to the protected route, else redirect to the auth_url with the referer set as the continuation URL.

Link to this function

create_jwt_session(conn, claims)

init/1 initialises the options passed in and makes them available in the lifecycle of the call/2 invocation (below). We pass in the auth_url key/value with the URL of the Auth service to redirect to if session is invalid/expired.

logout/1 does exactly what you expect; logs the person out of your app. recieves a conn (Plug.Conn) and unsets the session. This is super-useful in testing as we can easily reset a session.