diff --git a/default.nix b/default.nix index cbc29a6..1e1f912 100644 --- a/default.nix +++ b/default.nix @@ -20,7 +20,7 @@ mixRelease rec { mixFodDeps = fetchMixDeps { pname = "mix-deps-${pname}"; inherit version src; - sha256 = "sha256-p74p7Dpi1xzddD+dygKF5cSLDATNKRXziKPNQgIhRPc="; + sha256 = "sha256-tBWcGVLXEH1A55snOrSiA3Z3T0T8AHlpf0p5qi2nObw="; }; postBuild = '' ln -sfv ${tailwindcss}/bin/tailwindcss _build/tailwind-linux-x64 diff --git a/lib/sso_bsn/interactive.ex b/lib/sso_bsn/interactive.ex index c775280..061b099 100644 --- a/lib/sso_bsn/interactive.ex +++ b/lib/sso_bsn/interactive.ex @@ -36,7 +36,8 @@ defmodule SsoBsn.Interactive do "client_secret_post", "client_secret_jwt", "private_key_jwt" - ] + ], + id_token_signature_alg: "RS256" } |> Map.merge(opts |> Enum.into(%{})) ) diff --git a/lib/sso_bsn_web/controllers/openid/configuration.ex b/lib/sso_bsn_web/controllers/openid/configuration.ex index eb0b77f..3535ac4 100644 --- a/lib/sso_bsn_web/controllers/openid/configuration.ex +++ b/lib/sso_bsn_web/controllers/openid/configuration.ex @@ -1,11 +1,14 @@ defmodule SsoBsnWeb.Openid.ConfigurationController do - use SsoBsnWeb, :controller + use SsoBsnWeb, :controller - def config(conn, _params) do - conn |> json(%{ - issuer: url(~p"/"), - authorization_endpoint: url(~p"/openid/authorize"), - token_endpoint: url(~p"/oauth/token") - }) - end + def config(conn, _params) do + conn + |> json(%{ + issuer: url(~p"/"), + authorization_endpoint: url(~p"/openid/authorize"), + token_endpoint: url(~p"/oauth/token"), + jwks_uri: url(~p"/openid/jwks"), + userinfo_endpoint: url(~p"/openid/userinfo") + }) + end end diff --git a/lib/sso_bsn_web/controllers/webfinger.ex b/lib/sso_bsn_web/controllers/webfinger.ex new file mode 100644 index 0000000..766cefd --- /dev/null +++ b/lib/sso_bsn_web/controllers/webfinger.ex @@ -0,0 +1,14 @@ +defmodule SsoBsnWeb.Webfinger do + use SsoBsnWeb, :controller + + plug :put_resp_content_type, "application/jrd+json" + + def webfinger(conn, %{ "resource" => <<"acct:", _::bitstring>> = resource_uri }) do + conn |> json(%{ + subject: resource_uri, + links: [ + %{ rel: "http://openid.net/specs/connect/1.0/issuer", href: url(~p"/") } + ] + }) + end +end diff --git a/lib/sso_bsn_web/resource_owners.ex b/lib/sso_bsn_web/resource_owners.ex index 2f1291c..2c895b4 100644 --- a/lib/sso_bsn_web/resource_owners.ex +++ b/lib/sso_bsn_web/resource_owners.ex @@ -34,5 +34,8 @@ defmodule SsoBsnWeb.ResourceOwners do @impl Boruta.Oauth.ResourceOwners - def claims(_resource_owner, _scope), do: %{} + def claims(resource_owner, _scope), do: %{ + username: resource_owner.username, + email: "#{resource_owner.username}@#{Application.get_env(:sso_bsn, :session_domain)}" + } end diff --git a/lib/sso_bsn_web/router.ex b/lib/sso_bsn_web/router.ex index 5525c5d..8e04481 100644 --- a/lib/sso_bsn_web/router.ex +++ b/lib/sso_bsn_web/router.ex @@ -15,6 +15,7 @@ defmodule SsoBsnWeb.Router do pipeline :api do plug :accepts, ["json"] + plug Corsica, origins: "*" end scope "/", SsoBsnWeb do @@ -111,8 +112,9 @@ defmodule SsoBsnWeb.Router do get "/authorize", AuthorizeController, :authorize end - scope "/.well-known", SsoBsnWeb.Openid do + scope "/.well-known", SsoBsnWeb do pipe_through :api - get "/openid-configuration", ConfigurationController, :config + get "/openid-configuration", Openid.ConfigurationController, :config + get "/webfinger", Webfinger, :webfinger end end diff --git a/mix.exs b/mix.exs index 906e727..0d3fe32 100644 --- a/mix.exs +++ b/mix.exs @@ -48,7 +48,8 @@ defmodule SsoBsn.MixProject do {:dns_cluster, "~> 0.1.1"}, {:plug_cowboy, "~> 2.5"}, {:wax_, "~> 0.6.0"}, - {:boruta, "~> 2.3.0"} + {:boruta, "~> 2.3.0"}, + {:corsica, "~> 2.1.0"} ] end diff --git a/mix.lock b/mix.lock index 860849f..8980ab8 100644 --- a/mix.lock +++ b/mix.lock @@ -6,6 +6,7 @@ "cbor": {:hex, :cbor, "1.0.1", "39511158e8ea5a57c1fcb9639aaa7efde67129678fee49ebbda780f6f24959b0", [:mix], [], "hexpm", "5431acbe7a7908f17f6a9cd43311002836a34a8ab01876918d8cfb709cd8b6a2"}, "cc_precompiler": {:hex, :cc_precompiler, "0.1.8", "933a5f4da3b19ee56539a076076ce4d7716d64efc8db46fd066996a7e46e2bfd", [:mix], [{:elixir_make, "~> 0.7.3", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "176bdf4366956e456bf761b54ad70bc4103d0269ca9558fd7cee93d1b3f116db"}, "comeonin": {:hex, :comeonin, "5.4.0", "246a56ca3f41d404380fc6465650ddaa532c7f98be4bda1b4656b3a37cc13abe", [:mix], [], "hexpm", "796393a9e50d01999d56b7b8420ab0481a7538d0caf80919da493b4a6e51faf1"}, + "corsica": {:hex, :corsica, "2.1.3", "dccd094ffce38178acead9ae743180cdaffa388f35f0461ba1e8151d32e190e6", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "616c08f61a345780c2cf662ff226816f04d8868e12054e68963e95285b5be8bc"}, "cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},