Sake.Auth.Store behaviour (Sake v0.1.0)

Copy Markdown View Source

Where clients, codes, tokens and consents live. Implemented by Sake.Auth.Store.ETS and Sake.Auth.Store.Ecto.

Summary

Callbacks

Marks a refresh token used now, if and only if it was unused, atomically: two concurrent calls for the same hash must not both succeed. Returns the record as it was before this call.

Forgets the approval for one resource, or for every resource with :all.

Deletes the codes and tokens that expired by now, and the consents inserted before consents_before whose subject, client and resource have no live (unexpired, unrevoked) refresh token left.

Remembers an approval, keyed by subject, client and resource (replacing an earlier one).

Types

state()

@type state() :: term()

Callbacks

consume_code(state, t)

@callback consume_code(state(), String.t()) :: {:ok, Sake.Auth.Code.t()} | :error

consume_refresh(state, t)

@callback consume_refresh(state(), String.t()) ::
  {:ok, Sake.Auth.TokenRecord.t()}
  | {:error, :used, Sake.Auth.TokenRecord.t()}
  | :error

Marks a refresh token used now, if and only if it was unused, atomically: two concurrent calls for the same hash must not both succeed. Returns the record as it was before this call.

delete_client(state, t)

@callback delete_client(state(), String.t()) :: :ok

delete_consent(state, subject_id, client_id, resource)

@callback delete_consent(
  state(),
  subject_id :: String.t(),
  client_id :: String.t(),
  resource :: String.t() | :all
) :: :ok

Forgets the approval for one resource, or for every resource with :all.

get_client(state, t)

@callback get_client(state(), String.t()) :: {:ok, Sake.Auth.Client.t()} | :error

get_consent(state, subject_id, client_id, resource)

@callback get_consent(
  state(),
  subject_id :: String.t(),
  client_id :: String.t(),
  resource :: String.t()
) ::
  {:ok, Sake.Auth.Consent.t()} | :error

get_token(state, arg2, t)

@callback get_token(state(), :access | :refresh, String.t()) ::
  {:ok, Sake.Auth.TokenRecord.t()} | :error

init(keyword)

@callback init(keyword()) :: state()

list_clients(state)

@callback list_clients(state()) :: [Sake.Auth.Client.t()]

prune(state, now, consents_before)

@callback prune(state(), now :: DateTime.t(), consents_before :: DateTime.t()) :: :ok

Deletes the codes and tokens that expired by now, and the consents inserted before consents_before whose subject, client and resource have no live (unexpired, unrevoked) refresh token left.

put_client(state, t)

@callback put_client(state(), Sake.Auth.Client.t()) :: :ok

put_code(state, t)

@callback put_code(state(), Sake.Auth.Code.t()) :: :ok

put_consent(state, t)

@callback put_consent(state(), Sake.Auth.Consent.t()) :: :ok

Remembers an approval, keyed by subject, client and resource (replacing an earlier one).

put_token(state, t)

@callback put_token(state(), Sake.Auth.TokenRecord.t()) :: :ok

revoke_family(state, t)

@callback revoke_family(state(), String.t()) :: :ok

revoke_token(state, t)

@callback revoke_token(state(), String.t()) :: :ok

tokens_for_subject(state, t)

@callback tokens_for_subject(state(), String.t()) :: [Sake.Auth.TokenRecord.t()]