diff --git a/config/dev.exs b/config/dev.exs index 9ef39db..cf6694d 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -89,3 +89,5 @@ config :mv, :secret_key_base, "ryn7D6ssmIHQFWIks2sFiTGATgwwAR1+3bN8p7fy6qVtB8qnx # Signing Secret for Authentication config :mv, :token_signing_secret, "IwUwi65TrEeExwBXXFPGm2I7889NsL" + +config :mv, :oicd_client_secret , "krkpCYuLtaXUdQDcStaOQRBcfDSRvPdvpmllkraNRStBYMLXgXRlcTxoRkVDrLYv" diff --git a/docker-compose.yml b/docker-compose.yml index 3b4e8ec..03f0366 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,10 @@ +version: "3.5" + +networks: + local: + rauthy-test: + driver: bridge + services: db: image: postgres:17.5-alpine @@ -16,8 +23,37 @@ services: networks: - local -networks: - local: + mailcrab: + image: marlonb/mailcrab:latest + ports: + - "1080:1080" + networks: + - rauthy-test + + + rauthy: + container_name: rauthy-test + image: ghcr.io/sebadob/rauthy:latest + environment: + - LOCAL_TEST=true + - SMTP_URL=mailcrab + - SMTP_PORT=1025 + - SMTP_DANGER_INSECURE=true + - BOOTSTRAP_ADMIN_PASSWORD_PLAIN="RAUTHY" + #- HIQLITE=false + #- PG_HOST=db + #- PG_PORT=5432 + #- PG_USER=postgres + #- PG_PASSWORD=postgres + #- PG_DB_NAME=mv_dev + ports: + - "8080:8080" + depends_on: + - mailcrab + - db + networks: + - rauthy-test + - local volumes: postgres-data: diff --git a/lib/accounts/user.ex b/lib/accounts/user.ex index f07a57f..930bc0d 100644 --- a/lib/accounts/user.ex +++ b/lib/accounts/user.ex @@ -21,6 +21,22 @@ defmodule Mv.Accounts.User do end strategies do + oidc :rauthy do + client_id "mv" + base_url "http://localhost:8080/auth/v1" + redirect_uri "http://localhost:4000/auth/user/rauthy/callback" + auth_method :client_secret_jwt + #id_token_signed_response_alg "EdDSA" + #user_url "http://localhost:8080/auth/v1/oidc/userinfo" + #token_url "http://localhost:8080/auth/v1/oidc/token" + #authorize_url "http://localhost:8080/auth/v1/oidc/authorize" + registration_enabled? false + code_verifier true + client_secret fn _, _ -> + Application.fetch_env(:mv, :oicd_client_secret) + end + end + password :password do identity_field :email hash_provider AshAuthentication.BcryptProvider @@ -39,21 +55,23 @@ defmodule Mv.Accounts.User do prepare AshAuthentication.Preparations.FilterBySubject end - # read :sign_in_with_example do - # argument :user_info, :map, allow_nil?: false - # argument :oauth_tokens, :map, allow_nil?: false - # prepare AshAuthentication.Strategy.OAuth2.SignInPreparation + read :sign_in_with_rauthy do + argument :user_info, :map, allow_nil?: false + argument :oauth_tokens, :map, allow_nil?: false + prepare AshAuthentication.Strategy.OAuth2.SignInPreparation - # filter expr(email == get_path(^arg(:user_info), [:email])) - # end + filter expr(email == get_path(^arg(:user_info), [:email])) + end end + ## TODO: registration ergänzen, seed rausnehmen, oidc_id aus user_info map holen + attributes do uuid_primary_key :id attribute :email, :ci_string, allow_nil?: false, public?: true attribute :hashed_password, :string, sensitive?: true, allow_nil?: true - attribute :oicd_id, :string, allow_nil?: true + attribute :oidc_id, :string, allow_nil?: true end relationships do @@ -62,6 +80,7 @@ defmodule Mv.Accounts.User do identities do identity :unique_email, [:email] + identity :unique_oidc_id, [:oidc_id] end # You can customize this if you wish, but this is a safe default that diff --git a/lib/accounts/user_identity.exs b/lib/accounts/user_identity.exs new file mode 100644 index 0000000..1fe54f8 --- /dev/null +++ b/lib/accounts/user_identity.exs @@ -0,0 +1,15 @@ +defmodule Mv.Accounts.UserIdentity do + use Ash.Resource, + data_layer: AshPostgres.DataLayer, + extensions: [AshAuthentication.UserIdentity], + domain: Mv.Accounts + + user_identity do + user_resource Mv.Accounts.User + end + + postgres do + table "user_identities" + repo Mv.Repo + end +end diff --git a/lib/mv_web/controllers/auth_controller.ex b/lib/mv_web/controllers/auth_controller.ex index 913bc4b..f3dd287 100644 --- a/lib/mv_web/controllers/auth_controller.ex +++ b/lib/mv_web/controllers/auth_controller.ex @@ -22,6 +22,8 @@ defmodule MvWeb.AuthController do end def failure(conn, activity, reason) do + IO.puts(inspect(reason)) + message = case {activity, reason} do {_, diff --git a/lib/mv_web/controllers/page_html/home.html.heex b/lib/mv_web/controllers/page_html/home.html.heex index d72b03c..8cf0506 100644 --- a/lib/mv_web/controllers/page_html/home.html.heex +++ b/lib/mv_web/controllers/page_html/home.html.heex @@ -1,222 +1,52 @@ -<.flash_group flash={@flash} /> -
-- Peace of mind from prototype to production. -
-- Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale. -
-