View Source AshAuthentication.UserIdentity (ash_authentication v4.0.1)
An Ash extension which generates the default user identities resource.
The user identities resource is used to store information returned by remote authentication strategies (such as those provided by OAuth2) and maps them to your user resource(s). This provides the following benefits:
- A user can be signed in to multiple authentication strategies at once.
- For those provides which support it AshAuthentication can handle automatic refreshing of tokens.
Storage
User identities are expected to be relatively long-lived (although they're
deleted on log out), so should probably be stored using a permanent data layer
sush as ash_postgres
.
Usage
There is no need to define any attributes, etc. The extension will generate them all for you. As there is no other use-case for this resource it's unlikely that you will need to customise it.
defmodule MyApp.Accounts.UserIdentity do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication.UserIdentity],
domain: MyApp.Accounts
user_identity do
user_resource MyApp.Accounts.User
end
postgres do
table "user_identities"
repo MyApp.Repo
end
end
If you intend to operate with multiple user resources, you will need to define multiple user identity resources.