Lockspire.Storage.DeviceAuthorizationStore behaviour (lockspire v1.0.0)

Copy Markdown

Behaviour for storing and managing OAuth 2.0 Device Authorizations.

Summary

Types

device_poll_outcome()

@type device_poll_outcome() :: %{
  :result => device_poll_result(),
  optional(:device_authorization) => Lockspire.Domain.DeviceAuthorization.t(),
  optional(:effective_poll_interval_seconds) => pos_integer(),
  optional(:next_poll_allowed_at) => DateTime.t()
}

device_poll_result()

@type device_poll_result() ::
  :approved_ready
  | :client_mismatch
  | :consumed
  | :denied
  | :expired
  | :invalid_grant
  | :pending
  | :slow_down

Callbacks

consume_device_authorization(t, t, t)

@callback consume_device_authorization(String.t(), String.t(), DateTime.t()) ::
  {:ok, Lockspire.Domain.DeviceAuthorization.t()}
  | {:error, :invalid_state | term()}

fetch_device_authorization_by_device_code_hash(t)

@callback fetch_device_authorization_by_device_code_hash(String.t()) ::
  {:ok, Lockspire.Domain.DeviceAuthorization.t() | nil} | {:error, term()}

fetch_device_authorization_by_user_code_hash(t)

@callback fetch_device_authorization_by_user_code_hash(String.t()) ::
  {:ok, Lockspire.Domain.DeviceAuthorization.t() | nil} | {:error, term()}

fetch_device_authorization_by_verification_handle(t)

@callback fetch_device_authorization_by_verification_handle(String.t()) ::
  {:ok, Lockspire.Domain.DeviceAuthorization.t() | nil} | {:error, term()}

put_device_authorization(t)

@callback put_device_authorization(Lockspire.Domain.DeviceAuthorization.t()) ::
  {:ok, Lockspire.Domain.DeviceAuthorization.t()} | {:error, term()}

record_device_poll(t, t, t)

@callback record_device_poll(String.t(), String.t(), DateTime.t()) ::
  {:ok, device_poll_outcome()} | {:error, term()}

transition_device_authorization(t, list, map)

@callback transition_device_authorization(
  String.t(),
  [Lockspire.Domain.DeviceAuthorization.status()],
  map()
) :: {:ok, Lockspire.Domain.DeviceAuthorization.t()} | {:error, term()}