Gamend.OAuthSessions (gamend_core v1.0.1216)

Copy Markdown View Source

Helpers for creating and retrieving short-lived OAuth sessions.

Summary

Functions

A session that may still accept a callback: it exists, is pending, was started for provider, and is inside pending_ttl_seconds/0.

How long a session may sit in pending before a callback stops being accepted.

Functions

create_session(session_id, attrs \\ %{})

@spec create_session(String.t(), map()) ::
  {:ok, Gamend.OAuthSession.t()} | {:error, Ecto.Changeset.t()}

get_pending_session(session_id, provider \\ nil)

@spec get_pending_session(String.t(), String.t() | nil) ::
  Gamend.OAuthSession.t() | nil

A session that may still accept a callback: it exists, is pending, was started for provider, and is inside pending_ttl_seconds/0.

Returns nil otherwise, so a stale, replayed or provider-mismatched state is indistinguishable from one that was never issued.

get_session(session_id)

@spec get_session(String.t()) :: Gamend.OAuthSession.t() | nil

pending_ttl_seconds()

@spec pending_ttl_seconds() :: pos_integer()

How long a session may sit in pending before a callback stops being accepted.

An OAuth round trip is seconds; the only thing a long window buys is time for someone to hand a started flow's URL to another person and have that person's consent land in the starter's session.

update_session(session_id, attrs)

@spec update_session(String.t(), map()) ::
  {:ok, Gamend.OAuthSession.t()} | {:error, Ecto.Changeset.t()} | :not_found