WardrikVault. Grants behaviour
(wardrik_vault v0.1.0-rc.1)
Copy Markdown
The behaviour for grants: credentials a principal gives by authorizing an account, like OAuth tokens.
{WardrikVault, name: MyApp.Vault, store: store, keys: keys, grants: {MyApp.OAuth, opts}}When a tool needs a credential, the vault calls:
renew/5if the principal holds it as a grant.ask/4if nobody holds it, or the grant won't unseal.refused/4when a service refuses the grant.
Each callback gets the vault's name first and the module's opts last.
Write what comes back from authorizing with WardrikVault.put/5 and kind: :grant. Pass
:if_vsn so two renewals never write over each other.
Summary
Callbacks
Returns {:authorize, url} for the principal to authorize name at, or {:error, :not_found}.
Called when a service refuses the grant held as name.
Returns the credential grant gives. Renews it first if it has run out.
Types
@type grant() :: %{value: binary(), vsn: WardrikStore.vsn()}
A grant as the vault holds it. vsn is the version to write a renewal over.
Callbacks
@callback ask(GenServer.name(), String.t(), WardrikCore.Principal.t(), opts :: term()) :: {:authorize, String.t()} | {:error, term()}
Returns {:authorize, url} for the principal to authorize name at, or {:error, :not_found}.
@callback refused(GenServer.name(), String.t(), WardrikCore.Principal.t(), opts :: term()) :: :ok
Called when a service refuses the grant held as name.
@callback renew( GenServer.name(), String.t(), WardrikCore.Principal.t(), grant(), opts :: term() ) :: {:ok, term()} | {:authorize, String.t()} | {:error, term()}
Returns the credential grant gives. Renews it first if it has run out.