Pow v1.0.13 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{Pow.Store.CredentialsCache, backend: Pow.Store.Backend.EtsCache}
. ThePow.Store.Backend.EtsCache
backend store can be changed with the:cache_store_backend
option.:cache_store_backend
- the backend cache store. This value defaults toPow.Store.Backend.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
Configures the connection for Pow, and fetches 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 assigned to the conn.
Calls fetch/2
and assigns the current user to the conn.
Fetches session from credentials cache.
Link to this section Functions
call(conn, config) View Source
Configures the connection for Pow, and fetches user.
:plug
is appended to the passed configuration, so the current plug will
be used in any subsequent calls to create, update and delete user
credentials from the connection. The configuration is then set for the
conn with Pow.Plug.put_config/2
.
If a user can't be fetched with Pow.Plug.current_user/2
, do_fetch/2
will be called.
create(conn, user, config)
View Source
create(Plug.Conn.t(), map(), Pow.Config.t()) :: {Plug.Conn.t(), map()}
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.
See do_create/3
for more.
delete(conn, config)
View Source
delete(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()
delete(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()
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
.
See do_delete/2
for more.
do_create(conn, user, config)
View Source
do_create(Plug.Conn.t(), map(), Pow.Config.t()) :: Plug.Conn.t()
do_create(Plug.Conn.t(), map(), Pow.Config.t()) :: Plug.Conn.t()
Calls create/3
and assigns the current user.
The user is assigned to the conn with Pow.Plug.assign_current_user/3
.
do_delete(conn, config)
View Source
do_delete(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()
do_delete(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()
Calls delete/2
and removes the current user assigned to the conn.
The user assigned is removed from the conn with
Pow.Plug.assign_current_user/3
.
do_fetch(conn, config)
View Source
do_fetch(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()
do_fetch(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()
Calls fetch/2
and assigns the current user to the conn.
The user is assigned to the conn with Pow.Plug.assign_current_user/3
.
fetch(conn, config)
View Source
fetch(Plug.Conn.t(), Pow.Config.t()) :: {Plug.Conn.t(), map() | nil}
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
.
See do_fetch/2
for more.