Guardian.Plug
Guardian.Plug contains functions that assist with interacting with Guardian via Plugs.
Guardian.Plug is not itself a plug.
Example
Guarian.Plug.sign_in(conn, user)
Guardian.Plug.sign_in(conn, user, :csrf)
Guardian.Plug.sign_in(conn, user, :csrf, %{ claims: "i", make: true, key: :secret }) # stores this JWT in a different location (keyed by :secret)
Example
Guardian.Plug.sign_out(conn) # sign out all sessions
Guardian.Plug.sign_out(conn, :secret) # sign out only the :secret session
Summary↑
| claims(conn, the_key \\ :default) | Fetch the currently verified claims from the current request |
| current_resource(conn, the_key \\ :default) | Fetch the currently authenticated resource if loaded, optionally located at a location (key) |
| current_token(conn, the_key \\ :default) | Fetch the currently verified token from the request. optionally located at a location (key) |
| sign_in(conn, object) | Sign in a resource (that your configured serializer knows about) into the current web session |
| sign_in(conn, object, type) | Sign in a resource (that your configured serializer knows about) into the current web session |
| sign_in(conn, object, type, claims) | Same as sign_in/3 but also encodes all claims into the JWT |
| sign_out(conn, the_key \\ :all) | Sign out of a session |
Functions
Fetch the currently verified claims from the current request
Fetch the currently authenticated resource if loaded, optionally located at a location (key)
Fetch the currently verified token from the request. optionally located at a location (key)
Specs:
- sign_in(Plug.Conn.t, any) :: Plug.Conn.t
Sign in a resource (that your configured serializer knows about) into the current web session.
Specs:
- sign_in(Plug.Conn.t, any, atom | String.t) :: Plug.Conn.t
Sign in a resource (that your configured serializer knows about) into the current web session.
By specifying the ‘type’ of the token, you’re setting the aud field in the JWT.
Using the csrf type is special. It will encode the csrf token into the token, and that token is only useful when paired with that csrf
Specs:
- sign_in(Plug.Conn.t, any, atom | String.t, Map) :: Plug.Conn.t
Same as sign_in/3 but also encodes all claims into the JWT.
The :key key in the claims map is special in that it sets the location of the storage.
Sign out of a session.
If no key is specified, the entire session is cleared. Otherwise, only the location specified is cleared