View Source DSL: AshAuthentication.TokenResource
This is an Ash resource extension which generates the default token resource.
The token resource is used to store information about tokens that should not be shared with the end user. It does not actually contain any tokens.
- When an authentication token has been revoked
- When a confirmation token has changes to apply
The information stored in this resource is essentially ephemeral - all tokens have an expiry date, so it doesn't make sense to keep them after that time has passed. However, if you have any tokens with very long expiry times then we suggest you store this resource in a resilient data-layer such as Postgres.
There is no need to define any attributes or actions (although you can if you want). The extension will wire up everything that's needed for the token system to function.
defmodule MyApp.Accounts.Token do use Ash.Resource, data_layer: AshPostgres.DataLayer, extensions: [AshAuthentication.TokenResource] token do api MyApp.Accounts end postgres do table "tokens" repo MyApp.Repo end end
Whilst it is possible to have multiple token resources, there is no need to do so.
Once a token has expired there's no point in keeping the information it refers
to, so expired tokens can be automatically removed by adding the
AshAuthentication.Supervisor to your application supervision tree. This
will start the
periodically scans and removes any expired records.
Configuration options for this token resource
||The Ash API to use to access this resource.|
||The name of the action used to remove expired tokens.|
||The name of the action use to find all expired tokens. Used internally by the `expunge_expired` action.|
||How often to remove expired records. How often to scan this resource for records which have expired, and thus can be removed.|
||The name of the action to use to store a token. Used if `store_all_tokens?` is enabled in your authentication resource.|
||The name of the action used to retrieve tokens from the store. Used if `require_token_presence_for_authentication?` is enabled in your authentication resource.|
Configuration options for token revocation
||The name of the action used to revoke tokens.|
||The name of the action used to check if a token is revoked.|
Configuration options for confirmation tokens
||The name of the action used to store confirmation changes.|
||The name of the action used to get confirmation changes.|