feat: add oidc login using keycloak
This commit is contained in:
parent
630aec22cf
commit
00d15dfd47
2 changed files with 44 additions and 1 deletions
|
|
@ -20,6 +20,21 @@ defmodule Putzplan.Accounts.User do
|
||||||
store_all_tokens? true
|
store_all_tokens? true
|
||||||
require_token_presence_for_authentication? true
|
require_token_presence_for_authentication? true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
strategies do
|
||||||
|
oidc :oidc do
|
||||||
|
client_id "putzplan"
|
||||||
|
base_url "http://localhost:8080/realms/master/"
|
||||||
|
client_secret "Kc3DkJiIrIr59HQhDmneqqB3iy6H8gxH"
|
||||||
|
nonce true
|
||||||
|
redirect_uri "http://localhost:4000/auth"
|
||||||
|
authorization_params [scope: "profile email"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
identities do
|
||||||
|
identity :id, [:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
sqlite do
|
sqlite do
|
||||||
|
|
@ -36,6 +51,24 @@ defmodule Putzplan.Accounts.User do
|
||||||
get? true
|
get? true
|
||||||
prepare AshAuthentication.Preparations.FilterBySubject
|
prepare AshAuthentication.Preparations.FilterBySubject
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create :register_with_oidc do
|
||||||
|
argument :user_info, :map, allow_nil?: false
|
||||||
|
argument :oauth_tokens, :map, allow_nil?: false
|
||||||
|
upsert? true
|
||||||
|
upsert_identity :id
|
||||||
|
|
||||||
|
change AshAuthentication.GenerateTokenChange
|
||||||
|
|
||||||
|
change fn changeset, _ctx ->
|
||||||
|
user_info = Ash.Changeset.get_argument(changeset, :user_info)
|
||||||
|
dbg(user_info)
|
||||||
|
|
||||||
|
changeset
|
||||||
|
|> Ash.Changeset.change_attribute(:name, user_info["name"])
|
||||||
|
|> Ash.Changeset.change_attribute(:id, user_info["sub"])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
policies do
|
policies do
|
||||||
|
|
@ -49,6 +82,7 @@ defmodule Putzplan.Accounts.User do
|
||||||
end
|
end
|
||||||
|
|
||||||
attributes do
|
attributes do
|
||||||
uuid_primary_key :id
|
attribute :id, :uuid, allow_nil?: false, primary_key?: true
|
||||||
|
attribute :name, :string, allow_nil?: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
9
priv/repo/migrations/20250405114509_add_user_name.exs
Normal file
9
priv/repo/migrations/20250405114509_add_user_name.exs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Putzplan.Repo.Migrations.AddUserName do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:users, primary_key: false) do
|
||||||
|
add :name, :string, null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue