From 36fab0cd5053b73c39bd9b245f73ca5f6346109c Mon Sep 17 00:00:00 2001 From: yusing Date: Tue, 22 Apr 2025 03:55:43 +0800 Subject: [PATCH] fix(oidc): simplify and fix oidc middleware url handling --- internal/api/v1/auth/oidc.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/internal/api/v1/auth/oidc.go b/internal/api/v1/auth/oidc.go index 2643a99..65534cd 100644 --- a/internal/api/v1/auth/oidc.go +++ b/internal/api/v1/auth/oidc.go @@ -201,17 +201,12 @@ func (auth *OIDCProvider) RedirectLoginPage(w http.ResponseWriter, r *http.Reque Path: "/", }) - redirURL := auth.oauthConfig.AuthCodeURL(state) + var redirURL string if auth.isMiddleware { - u, err := r.URL.Parse(redirURL) - if err != nil { - gphttp.ServerError(w, r, err) - return - } - q := u.Query() - q.Set("redirect_uri", "https://"+r.Host+OIDCMiddlewareCallbackPath+q.Get("redirect_uri")) - u.RawQuery = q.Encode() - redirURL = u.String() + optOverrideRedirectURL := oauth2.SetAuthURLParam("redirect_uri", "https://"+r.Host+OIDCMiddlewareCallbackPath) + redirURL = auth.oauthConfig.AuthCodeURL(state, optOverrideRedirectURL) + } else { + redirURL = auth.oauthConfig.AuthCodeURL(state) } http.Redirect(w, r, redirURL, http.StatusTemporaryRedirect) }