From 5040a2fe3c89c4adb8f0fe173764c59785d903ad Mon Sep 17 00:00:00 2001 From: Josef Andersson Date: Sun, 30 Apr 2023 12:09:42 +0200 Subject: [PATCH] Respect ExternalUrl for oauth --- internal/web/auth.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/web/auth.go b/internal/web/auth.go index 9e402b6..5e07826 100644 --- a/internal/web/auth.go +++ b/internal/web/auth.go @@ -231,7 +231,13 @@ func oauth(ctx echo.Context) error { } giteaUrl := trimGiteaUrl() - httpDomain := httpProtocol + "://" + ctx.Request().Host + + var opengistUrl string + if config.C.ExternalUrl != "" { + opengistUrl = config.C.ExternalUrl + } else { + opengistUrl = httpProtocol + "://" + ctx.Request().Host + } switch provider { case "github": @@ -239,7 +245,7 @@ func oauth(ctx echo.Context) error { github.New( config.C.GithubClientKey, config.C.GithubSecret, - httpDomain+"/oauth/github/callback"), + opengistUrl+"/oauth/github/callback"), ) case "gitea": @@ -247,7 +253,7 @@ func oauth(ctx echo.Context) error { gitea.NewCustomisedURL( config.C.GiteaClientKey, config.C.GiteaSecret, - httpDomain+"/oauth/gitea/callback", + opengistUrl+"/oauth/gitea/callback", giteaUrl+"/login/oauth/authorize", giteaUrl+"/login/oauth/access_token", giteaUrl+"/api/v1/user"),