Curator.SessionKeeper v0.1.0 Curator.SessionKeeper.Plug

Curator.SessionKeeper.Plug contains functions that assist with interacting with Curator.SessionKeeper via Plugs.

Curator.SessionKeeper.Plug is not itself a plug.

Example

Curator.SessionKeeper.Plug.sign_in(conn, user)
Curator.SessionKeeper.Plug.sign_in(conn, user)

# stores this claims in a different location (keyed by :secret)
Curator.SessionKeeper.Plug.sign_in(
  conn,
  user,
  %{ claims: "i", make: true, key: :secret }
)

Example

Curator.SessionKeeper.Plug.sign_out(conn) # sign out all sessions
Curator.SessionKeeper.Plug.sign_out(conn, :secret) # sign out only the :secret session

Then use the Curator.SessionKeeper.Plug helpers to look up claims and current_resource.

Example

Curator.SessionKeeper.Plug.claims(conn)
Curator.SessionKeeper.Plug.current_resource(conn)

Summary

Functions

A simple check to see if a request is authenticated

A simple check to see if a request is authenticated

Fetch the currently verified claims from the current request

Fetch the currently authenticated resource if loaded, optionally located at a location (key)

Sign in a resource (that your configured serializer knows about) into the current web session

Same as sign_in/3 but also encodes all claims into the default claims

Sign out of a session

Functions

authenticated?(conn)
authenticated?(Plug.Conn.t) :: atom

A simple check to see if a request is authenticated

authenticated?(conn, the_key)
authenticated?(Plug.Conn.t, atom) :: atom

A simple check to see if a request is authenticated

claims(conn, the_key \\ :default)
claims(Plug.Conn.t, atom) ::
  {:ok, map} |
  {:error, atom | String.t}

Fetch the currently verified claims from the current request

current_resource(conn, the_key \\ :default)
current_resource(Plug.Conn.t, atom) :: any | nil

Fetch the currently authenticated resource if loaded, optionally located at a location (key)

sign_in(conn, object)
sign_in(Plug.Conn.t, any) :: Plug.Conn.t

Sign in a resource (that your configured serializer knows about) into the current web session.

sign_in(conn, object, new_claims)
sign_in(Plug.Conn.t, any, map) :: Plug.Conn.t

Same as sign_in/3 but also encodes all claims into the default claims.

The :key key in the claims map is special in that it sets the location of the storage.

Example

Curator.SessionKeeper.sign_in(conn, user, :access)
sign_out(conn, the_key \\ :all)

Sign out of a session.

If no key is specified, the entire session is cleared. Otherwise, only the location specified is cleared