test for authentication and oidc closes #120 #123

Merged
carla merged 2 commits from feature/oidc_tests into main 2025-07-31 14:25:31 +02:00
Showing only changes of commit 6907b2ed3c - Show all commits

View file

@ -105,6 +105,8 @@ defmodule Mv.Accounts.User do
upsert? true
upsert_identity :unique_oidc_id
validate &__MODULE__.validate_oidc_id_present/2
change AshAuthentication.GenerateTokenChange
change fn changeset, _ctx ->
@ -125,6 +127,16 @@ defmodule Mv.Accounts.User do
end
end
def validate_oidc_id_present(changeset, _context) do
user_info = Ash.Changeset.get_argument(changeset, :user_info) || %{}
if is_binary(user_info["sub"]) or is_binary(user_info["id"]) do
:ok
else
{:error, [user_info: "OIDC user_info must contain a non-empty 'sub' or 'id' field"]}
end
end
attributes do
uuid_primary_key :id