Pow v1.0.1 Pow.Plug.Session View Source

This plug will handle user authorization using session.

Example

plug Plug.Session,
  store: :cookie,
  key: "_my_app_demo_key",
  signing_salt: "secret"

plug Pow.Plug.Session,
  repo: MyApp.Repo,
  user: MyApp.User,
  current_user_assigns_key: :current_user,
  session_key: "auth",
  session_store: {Pow.Store.CredentialsCache,
                  ttl: :timer.minutes(30),
                  namespace: "credentials"},
  session_ttl_renewal: :timer.minutes(15),
  cache_store_backend: Pow.Store.Backend.EtsCache,
  users_context: Pow.Ecto.Users

Configuration options

  • :session_key - session key name, defaults to "auth". If :otp_app is used it'll automatically prepend the key with the :otp_app value.

  • :session_store - the credentials cache store. This value defaults to {CredentialsCache, backend: EtsCache}. The EtsCache backend store can be changed with the :cache_store_backend option.

  • :cache_store_backend - the backend cache store. This value defaults to EtsCache.

  • :session_ttl_renewal - the ttl in milliseconds to trigger renewal of sessions. Defaults to 15 minutes in miliseconds.

Link to this section Summary

Functions

Initializes the connection for Pow, and assigns current user

Create new session with a randomly generated unique session id

Delete an existing session in the credentials cache

Calls create/3 and assigns the current user

Calls delete/2 and removes the current user assign

Calls fetch/2 and assigns the current user

Fetches session from credentials cache

Link to this section Functions

Initializes the connection for Pow, and assigns current user.

If a user is not already assigned, do_fetch/2 will be called. :mod is added to the private pow configuration key, so it can be used in subsequent calls to create, update and delete user credentials from the connection.

Link to this function

create(conn, user, config) View Source
create(Plug.Conn.t(), map(), Pow.Config.t()) :: {Plug.Conn.t(), map()}

Create new session with a randomly generated unique session id.

This will store the unique session id with user credentials in the credentials cache. The session id will be stored in the connection with Plug.Conn.put_session/3. Any existing sessions will be deleted first with delete/2.

The unique session id will be prepended by the :otp_app configuration value, if present.

Delete an existing session in the credentials cache.

This will delete a session in the credentials cache with the session id fetched through Plug.Conn.get_session/2. The session in the connection is deleted too with Plug.Conn.delete_session/2.

Link to this function

do_create(conn, user, config) View Source
do_create(Plug.Conn.t(), map(), Pow.Config.t()) :: Plug.Conn.t()

Calls create/3 and assigns the current user.

Link to this function

do_delete(conn, config) View Source
do_delete(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()

Calls delete/2 and removes the current user assign.

Calls fetch/2 and assigns the current user.

Link to this function

fetch(conn, config) View Source
fetch(Plug.Conn.t(), Pow.Config.t()) :: {Plug.Conn.t(), map() | nil}

Fetches session from credentials cache.

This will fetch a session from the credentials cache with the session id fetched through Plug.Conn.get_session/2 session. If the credentials are stale (timestamp is older than the :session_ttl_renewal value), the session will be regenerated with create/3.