AttestoPhoenix.Revocation (AttestoPhoenix v5.0.0)

Copy Markdown View Source

Cut off a subject, a client, or a session: delete their unredeemed authorization codes and revoke their refresh-token families.

Repo.transaction(fn ->
  MyApp.Accounts.disable!(user)
  {:ok, _counts} = AttestoPhoenix.Revocation.revoke_subject(config, user.id)
end)

Each function calls the configured :code_store's Attesto.CodeStore.delete_unclaimed/1 and the configured :refresh_store's Attesto.RefreshStore.revoke_families/1. With the bundled Ecto stores both run on the configured repo and open no outer transaction of their own, so a call made inside the host's transaction commits or rolls back with it. Put the call in the same transaction as the change that makes the subject or client ineligible; otherwise a grant issued between the two is missed.

Lock order

Lock authorization-code rows before refresh families. The bundled stores then lock families in ascending family-id order and rows in ascending id order within each family, taking the family advisory lock before its rows. Hosts combining these operations must use the same order, including across multiple calls in one transaction. Scheduled sweeps release each step's locks before the next step. Sweeper.sweep_once/2 instead remains inside the caller's transaction; do not run it concurrently with grant writes.

What is and is not revoked

  • Unredeemed authorization codes are deleted; redeeming one afterwards fails as an unknown code.
  • Refresh-token families are revoked for good: every token removed and the family marked so no successor can be inserted.
  • Access tokens already issued are not revoked. A self-contained JWT access token stays valid until it expires unless the protected resource consults introspection or a denylist. Keep :access_token_ttl short, or have the resource check the subject's status, when immediate cut-off matters.

Stores

A store that is not configured contributes 0. A configured store that does not implement the callback raises ArgumentError: reporting success while that store's grants stay live would be worse than failing.

Summary

Functions

The general form: criteria is a keyword list of :subject, :client_id and/or :sid, ANDed (see Attesto.RevocationCriteria).

Delete the unredeemed codes and revoke the refresh families issued to client_id, for any subject.

Delete the unredeemed codes and revoke the refresh families issued under the host session sid (the :sid the host's authentication callback returned).

Delete the unredeemed codes and revoke the refresh families issued for subject, to any client.

Types

counts()

@type counts() :: %{
  codes: non_neg_integer(),
  device_codes: non_neg_integer(),
  ciba_requests: non_neg_integer(),
  pre_authorized_codes: non_neg_integer(),
  refresh_families: non_neg_integer()
}

Functions

revoke(config, criteria)

The general form: criteria is a keyword list of :subject, :client_id and/or :sid, ANDed (see Attesto.RevocationCriteria).

revoke_client(config, client_id)

@spec revoke_client(AttestoPhoenix.Config.t(), String.t()) :: {:ok, counts()}

Delete the unredeemed codes and revoke the refresh families issued to client_id, for any subject.

revoke_session(config, sid)

@spec revoke_session(AttestoPhoenix.Config.t(), String.t()) :: {:ok, counts()}

Delete the unredeemed codes and revoke the refresh families issued under the host session sid (the :sid the host's authentication callback returned).

revoke_subject(config, subject)

@spec revoke_subject(AttestoPhoenix.Config.t(), String.t()) :: {:ok, counts()}

Delete the unredeemed codes and revoke the refresh families issued for subject, to any client.