View Source Charon.Utils (Charon v1.3.4)

Utility functions, mainly getters and setters for module internals.

Link to this section Summary

Functions

Get auth errors, if present.

Get the payload of the bearer token, if present.

Get current session, if present.

Get token signature transport mechanism, if present.

Get tokens, if present.

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

Set user id for session creation

Link to this section Functions

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

Get auth errors, if present.

Link to this function

get_bearer_token_payload(conn)

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

Get the payload of the bearer token, if present.

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

Get current session, if present.

Link to this function

get_token_signature_transport(conn)

View Source
@spec get_token_signature_transport(Plug.Conn.t()) :: atom() | nil

Get token signature transport mechanism, if present.

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

Get tokens, if present.

Link to this function

set_token_signature_transport(conn, token_signature_transport)

View Source
@spec set_token_signature_transport(Plug.Conn.t(), binary() | :bearer | :cookie) ::
  Plug.Conn.t()

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

examples-doctests

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") |> get_token_signature_transport()
iex> :cookie = %Conn{} |> set_token_signature_transport(:cookie) |> get_token_signature_transport()

iex> set_token_signature_transport(%Conn{}, "anything else")
** (FunctionClauseError) no function clause matching in Charon.Internal.parse_sig_transport/1
Link to this function

set_user_id(conn, user_id)

View Source
@spec set_user_id(Plug.Conn.t(), any()) :: Plug.Conn.t()

Set user id for session creation