Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserIdentity: Not generating a user_info map #737

Open
KyleCulp opened this issue Jun 30, 2024 · 0 comments
Open

UserIdentity: Not generating a user_info map #737

KyleCulp opened this issue Jun 30, 2024 · 0 comments

Comments

@KyleCulp
Copy link

While AshAuthentication.Strategy.OAuth2.IdentityChange does handle multiple identities, and works well with providing a custom identity to individual OAuth providers (say a MyApp.Accounts.Identities.Github & MyApp.Accounts.Identities.Google), it does not generate a :user_info map column to save the information on the identity, like it does for :access_token, :uid, etc.

You could easily have a :google_information column on your MyApp.Accounts.User and save the information like so, but it seems incredibly complex to save the information in the MyApp.Accounts.Identities.Google resource. An easy example of saving it is below.

create :register_with_google do
  argument :user_info, :map, allow_nil?: false
  argument :oauth_tokens, :map, allow_nil?: false
  upsert? true
  upsert_identity :email

  change AshAuthentication.GenerateTokenChange
  change AshAuthentication.Strategy.OAuth2.IdentityChange

  change fn changeset, _ ->
    user_info = Ash.Changeset.get_argument(changeset, :user_info)

    changeset
    |> Ash.Changeset.change_attributes(Map.take(user_info, ["email"]))
    |> Ash.Changeset.change_attribute(:google, user_info)
  end
end

This is easily doable, but to have a map on the actual Identity table would be very nice. I've attempted to create a custom change in the create action, but the way the Identity resource is handled by AshAuthentication.Strategy.OAuth2.IdentityChange made this challenging. Whether we're given the option to add attributes to the custom User Identity specific to each OAuth provider, or a generic :user_info map to dump all the info in, either would be incredibly helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant