From d921263e4364ec6e19266867167bb6501a296ef0 Mon Sep 17 00:00:00 2001 From: Spencer Collins Date: Tue, 12 Nov 2024 03:19:16 -0600 Subject: [PATCH 1/2] Get oauth base url from Endpoint.static_url --- config/runtime.exs | 2 -- lib/teiserver_web/views/api/o_auth/code_view.ex | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 394f660d8..bbf2b5300 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -183,5 +183,3 @@ if config_env() == :prod do bot_name: Teiserver.ConfigHelpers.get_env("TEI_DISCORD_BOT_NAME") end end - -config :teiserver, Teiserver.OAuth, issuer: "https://#{domain_name}" diff --git a/lib/teiserver_web/views/api/o_auth/code_view.ex b/lib/teiserver_web/views/api/o_auth/code_view.ex index 312c014a3..e48e7d1d3 100644 --- a/lib/teiserver_web/views/api/o_auth/code_view.ex +++ b/lib/teiserver_web/views/api/o_auth/code_view.ex @@ -22,7 +22,7 @@ defmodule TeiserverWeb.OAuth.CodeView do end def metadata(_) do - base = Application.fetch_env!(:teiserver, Teiserver.OAuth)[:issuer] + base = TeiserverWeb.Endpoint.static_url() %{ issuer: base, From c7842e2845452b9f6d12ba1c9f1bee394ff88948 Mon Sep 17 00:00:00 2001 From: Spencer Collins Date: Mon, 18 Nov 2024 22:02:35 -0600 Subject: [PATCH 2/2] Fix test after getting local oauth endpoint working --- .../controllers/o_auth/code_controller_test.exs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/teiserver_web/controllers/o_auth/code_controller_test.exs b/test/teiserver_web/controllers/o_auth/code_controller_test.exs index 71ef13b3e..eb0a1f021 100644 --- a/test/teiserver_web/controllers/o_auth/code_controller_test.exs +++ b/test/teiserver_web/controllers/o_auth/code_controller_test.exs @@ -319,11 +319,12 @@ defmodule TeiserverWeb.OAuth.CodeControllerTest do test "can query oauth metadata", %{conn: conn} do resp = json_response(get(conn, ~p"/.well-known/oauth-authorization-server"), 200) + endpoint = TeiserverWeb.Endpoint.static_url() assert resp == %{ - "issuer" => "https://beyondallreason.info", - "authorization_endpoint" => "https://beyondallreason.info/oauth/authorize", - "token_endpoint" => "https://beyondallreason.info/oauth/token", + "issuer" => "#{endpoint}", + "authorization_endpoint" => "#{endpoint}/oauth/authorize", + "token_endpoint" => "#{endpoint}/oauth/token", "token_endpoint_auth_methods_supported" => [ "none", "client_secret_post",