View Source Charon.Utils (Charon v3.2.0)

Utility functions, mainly getters and setters for module internals.

Summary

Functions

Get auth errors, if present.

Get the bearer token, if present.

Get the payload of the bearer token, if present.

Get current session, if present.

Get token signature transport mechanism, if present.

Get token transport mechanism, if present.

Get tokens, if present.

Put an auth error on the conn

Put a session on the conn

Put a token on the conn

Put a token payload on the conn

Set token signature transport mechanism. Must be one of "bearer", "cookie_only", "cookie" :bearer, :cookie_only or :cookie.

Set user id for session creation

Functions

get_auth_error(conn)

@spec get_auth_error(Plug.Conn.t()) :: binary() | nil

Get auth errors, if present.

get_bearer_token(conn)

@spec get_bearer_token(Plug.Conn.t()) :: map() | nil

Get the bearer token, if present.

get_bearer_token_payload(conn)

@spec get_bearer_token_payload(Plug.Conn.t()) :: map() | nil

Get the payload of the bearer token, if present.

get_session(conn)

@spec get_session(Plug.Conn.t()) :: Charon.Models.Session.t() | nil

Get current session, if present.

get_token_signature_transport(conn)

This function is deprecated. Use get_token_transport/2..
@spec get_token_signature_transport(Plug.Conn.t()) :: atom() | nil

Get token signature transport mechanism, if present.

get_token_transport(conn)

(since 3.1.0)
@spec get_token_transport(Plug.Conn.t()) :: atom() | nil

Get token transport mechanism, if present.

get_tokens(conn)

@spec get_tokens(Plug.Conn.t()) :: Charon.Models.Tokens.t() | nil

Get tokens, if present.

set_auth_error(conn, error)

@spec set_auth_error(Plug.Conn.t(), any()) :: Plug.Conn.t()

Put an auth error on the conn

set_session(conn, session)

@spec set_session(Plug.Conn.t(), any()) :: Plug.Conn.t()

Put a session on the conn

set_token(conn, token)

@spec set_token(Plug.Conn.t(), any()) :: Plug.Conn.t()

Put a token on the conn

set_token_payload(conn, payload)

@spec set_token_payload(Plug.Conn.t(), any()) :: Plug.Conn.t()

Put a token payload on the conn

set_token_signature_transport(conn, token_signature_transport)

This function is deprecated. Use SessionPlugs.upsert_session/3 option :token_transport.
@spec set_token_signature_transport(
  Plug.Conn.t(),
  binary() | :cookie | :bearer | :cookie_only
) ::
  Plug.Conn.t()

Set token signature transport mechanism. Must be one of "bearer", "cookie_only", "cookie" :bearer, :cookie_only or :cookie.

This function only results in transports :bearer and :cookie, never in :cookie_only, in contrast with set_token_signature_transport/2, to maintain backwards compatibility.

Examples / doctests

iex> :bearer = %Conn{} |> set_token_signature_transport("bearer") |> get_token_signature_transport()
iex> :bearer = %Conn{} |> set_token_signature_transport(:bearer) |> get_token_signature_transport()
iex> :cookie = %Conn{} |> set_token_signature_transport("cookie_only") |> get_token_signature_transport()
iex> :cookie = %Conn{} |> set_token_signature_transport(:cookie_only) |> get_token_signature_transport()
iex> :cookie = %Conn{} |> set_token_signature_transport("cookie") |> get_token_signature_transport()
iex> :cookie = %Conn{} |> set_token_signature_transport(:cookie) |> get_token_signature_transport()

set_user_id(conn, user_id)

This function is deprecated. Use SessionPlugs.upsert_session/3 option :user_id.
@spec set_user_id(Plug.Conn.t(), any()) :: Plug.Conn.t()

Set user id for session creation