feat: support email scope to retrieve oidc info
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simon 2025-12-03 21:51:12 +01:00
parent 3d4020cf27
commit 613a5f2643
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2

View file

@ -69,7 +69,7 @@ defmodule Mv.Accounts.User do
# Default actions for framework/tooling integration: # Default actions for framework/tooling integration:
# - :read -> Standard read used across the app and by admin tooling. # - :read -> Standard read used across the app and by admin tooling.
# - :destroy-> Standard delete used by admin tooling and maintenance tasks. # - :destroy-> Standard delete used by admin tooling and maintenance tasks.
# #
# NOTE: :create is INTENTIONALLY excluded from defaults! # NOTE: :create is INTENTIONALLY excluded from defaults!
# Using a default :create would bypass email-synchronization logic. # Using a default :create would bypass email-synchronization logic.
# Always use one of these explicit create actions instead: # Always use one of these explicit create actions instead:
@ -185,7 +185,9 @@ defmodule Mv.Accounts.User do
oidc_user_info = Ash.Changeset.get_argument(changeset, :oidc_user_info) oidc_user_info = Ash.Changeset.get_argument(changeset, :oidc_user_info)
# Get the new email from OIDC user_info # Get the new email from OIDC user_info
new_email = Map.get(oidc_user_info, "preferred_username") # Support both "email" (standard OIDC) and "preferred_username" (Rauthy)
new_email =
Map.get(oidc_user_info, "email") || Map.get(oidc_user_info, "preferred_username")
changeset changeset
|> Ash.Changeset.change_attribute(:oidc_id, oidc_id) |> Ash.Changeset.change_attribute(:oidc_id, oidc_id)
@ -239,8 +241,11 @@ defmodule Mv.Accounts.User do
change fn changeset, _ctx -> change fn changeset, _ctx ->
user_info = Ash.Changeset.get_argument(changeset, :user_info) user_info = Ash.Changeset.get_argument(changeset, :user_info)
# Support both "email" (standard OIDC like Authentik, Keycloak) and "preferred_username" (Rauthy)
email = user_info["email"] || user_info["preferred_username"]
changeset changeset
|> Ash.Changeset.change_attribute(:email, user_info["preferred_username"]) |> Ash.Changeset.change_attribute(:email, email)
|> Ash.Changeset.change_attribute(:oidc_id, user_info["sub"] || user_info["id"]) |> Ash.Changeset.change_attribute(:oidc_id, user_info["sub"] || user_info["id"])
end end