From af8d2c74f60b191b6cfb77e570b806ec924ab7e2 Mon Sep 17 00:00:00 2001 From: yusing Date: Fri, 25 Apr 2025 11:10:21 +0800 Subject: [PATCH] revert(oidc): api breaking changes --- internal/api/handler.go | 8 ++------ internal/auth/oidc.go | 4 ++-- internal/auth/provider.go | 1 + internal/auth/userpass.go | 4 ++++ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/api/handler.go b/internal/api/handler.go index a340821..12f9785 100644 --- a/internal/api/handler.go +++ b/internal/api/handler.go @@ -96,12 +96,8 @@ func NewHandler(cfg config.ConfigInstance) http.Handler { } mux.HandleFunc("GET", "/v1/auth/check", auth.AuthCheckHandler) - mux.HandleFunc("GET", "/v1/auth/login", defaultAuth.LoginHandler) - mux.HandleFunc("GET", "/v1/auth/callback", defaultAuth.LoginHandler) + mux.HandleFunc("GET", "/v1/auth/redirect", defaultAuth.LoginHandler) + mux.HandleFunc("GET", "/v1/auth/callback", defaultAuth.PostAuthCallbackHandler) mux.HandleFunc("GET,POST", "/v1/auth/logout", defaultAuth.LogoutHandler) - switch authProvider := defaultAuth.(type) { - case *auth.OIDCProvider: - mux.HandleFunc("GET", "/v1/auth/postauth", authProvider.PostAuthCallbackHandler) - } return mux } diff --git a/internal/auth/oidc.go b/internal/auth/oidc.go index f2b92d7..115b793 100644 --- a/internal/auth/oidc.go +++ b/internal/auth/oidc.go @@ -44,8 +44,8 @@ const ( ) const ( - OIDCAuthInitPath = "/auth/init" - OIDCPostAuthPath = "/auth/postauth" + OIDCAuthInitPath = "/" + OIDCPostAuthPath = "/auth/callback" OIDCLogoutPath = "/auth/logout" ) diff --git a/internal/auth/provider.go b/internal/auth/provider.go index 7bd9aa3..71bff11 100644 --- a/internal/auth/provider.go +++ b/internal/auth/provider.go @@ -5,5 +5,6 @@ import "net/http" type Provider interface { CheckToken(r *http.Request) error LoginHandler(w http.ResponseWriter, r *http.Request) + PostAuthCallbackHandler(w http.ResponseWriter, r *http.Request) LogoutHandler(w http.ResponseWriter, r *http.Request) } diff --git a/internal/auth/userpass.go b/internal/auth/userpass.go index 80e86d2..dc5a42f 100644 --- a/internal/auth/userpass.go +++ b/internal/auth/userpass.go @@ -123,6 +123,10 @@ func (auth *UserPassAuth) LoginHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } +func (auth *UserPassAuth) PostAuthCallbackHandler(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/", http.StatusFound) +} + func (auth *UserPassAuth) LogoutHandler(w http.ResponseWriter, r *http.Request) { clearTokenCookie(w, r, auth.TokenCookieName()) http.Redirect(w, r, "/", http.StatusFound)