View Source Charon.AuthFlow (Charon v0.0.4-alpha)

An authentication flow that can be used to log in. A flow consists of stages, each of which has to be passed in order to log in. A stage consists of challenges, one of which has to be passed in order to pass the stage.

Link to this section Summary

Types

A set of auth flows.

t()

An authentication flow that can be used to log in. A flow consists of stages, each of which has to be passed in order to log in. A stage consists of challenges, one of which has to be passed in order to pass the stage.

Functions

After completing a challenge, pass the result to this function. If the challenge is completed successfully and it is the final stage of an auth flow, a session is created and tokens are handed out. If the challenge is completed successfully but it is not the final stage of an auth flow, the next stage is returned. If the challenge fails, the error is returned.

Initialize a new auth flow. Creates a protosession and a token to complete its auth flow with.

Create a flow set from a list of t:Charon.AuthFlow.t().

Verify a protosession token, load its protosession and find the requested challenge.

Create a challenge map (challenges mapped to their names) from a flow set.

Link to this section Types

@type flow_set() :: %{required(String.t()) => t()}

A set of auth flows.

@type t() :: %Charon.AuthFlow{name: String.t(), stages: [Charon.AuthFlow.Stage.t()]}

An authentication flow that can be used to log in. A flow consists of stages, each of which has to be passed in order to log in. A stage consists of challenges, one of which has to be passed in order to pass the stage.

Link to this section Functions

Link to this function

handle_challenge_result(result, flow_set, session, conn, config, opts \\ [])

View Source
@spec handle_challenge_result(
  {:ok, Plug.Conn.t(), map() | nil} | {:error, String.t() | map()},
  flow_set(),
  Charon.Models.Session.t(),
  Plug.Conn.t(),
  Charon.Config.t(),
  keyword()
) ::
  {:flow_complete, Plug.Conn.t(), map()}
  | {:challenge_complete, Plug.Conn.t(),
     %{next_stage: Charon.AuthFlow.Stage.t()}}
  | {:error, String.t() | map()}

After completing a challenge, pass the result to this function. If the challenge is completed successfully and it is the final stage of an auth flow, a session is created and tokens are handed out. If the challenge is completed successfully but it is not the final stage of an auth flow, the next stage is returned. If the challenge fails, the error is returned.

Link to this function

init(user, flow_set, flow_name, sig_transport, config)

View Source
@spec init(map() | struct(), flow_set(), String.t(), String.t(), Charon.Config.t()) ::
  {:ok, String.t(), Charon.AuthFlow.Stage.t()} | {:error, String.t()}

Initialize a new auth flow. Creates a protosession and a token to complete its auth flow with.

Link to this function

list_to_flow_set(flow_list)

View Source
@spec list_to_flow_set([t()]) :: flow_set()

Create a flow set from a list of t:Charon.AuthFlow.t().

Link to this function

process_token(token, flows, name, config)

View Source
@spec process_token(String.t(), flow_set(), String.t(), Charon.Config.t()) ::
  {:ok, Charon.AuthChallenge.t(), Charon.Models.Session.t()}
  | {:error, String.t()}

Verify a protosession token, load its protosession and find the requested challenge.

Link to this function

to_challenge_map(flow_set)

View Source
@spec to_challenge_map(flow_set()) :: %{
  required(String.t()) => Charon.AuthChallenge.t()
}

Create a challenge map (challenges mapped to their names) from a flow set.