View Source AshAuthentication.UserIdentity (ash_authentication v3.11.10)

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:

  1. A user can be signed in to multiple authentication strategies at once.
  2. 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]

  user_identity do
    api MyApp.Accounts
    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.

Dsl

Index

  • user_identity

Docs

user_identity

Configure identity options for this resource


  • :api (atom/0) - Required. The Ash API to use to access this resource.

  • :user_resource (atom/0) - Required. The user resource to which these identities belong.

  • :uid_attribute_name (atom/0) - The name of the uid attribute on this resource. The default value is :uid.

  • :strategy_attribute_name (atom/0) - The name of the strategy attribute on this resource. The default value is :strategy.

  • :user_id_attribute_name (atom/0) - The name of the user_id attribute on this resource. The default value is :user_id.

  • :access_token_attribute_name (atom/0) - The name of the access_token attribute on this resource. The default value is :access_token.

  • :access_token_expires_at_attribute_name (atom/0) - The name of the access_token_expires_at attribute on this resource. The default value is :access_token_expires_at.

  • :refresh_token_attribute_name (atom/0) - The name of the refresh_token attribute on this resource. The default value is :refresh_token.

  • :upsert_action_name (atom/0) - The name of the action used to create and update records. The default value is :upsert.

  • :destroy_action_name (atom/0) - The name of the action used to destroy records. The default value is :destroy.

  • :read_action_name (atom/0) - The name of the action used to query identities. The default value is :read.

  • :user_relationship_name (atom/0) - The name of the belongs-to relationship between identities and users. The default value is :user.