fix(auth): change userpass to redirect to login and update documentation

This commit is contained in:
yusing
2025-09-14 21:11:20 +08:00
parent 025ebab1ce
commit 8b8969f033
5 changed files with 7 additions and 19 deletions

View File

@@ -5,14 +5,14 @@ import (
"github.com/yusing/go-proxy/internal/auth" "github.com/yusing/go-proxy/internal/auth"
) )
// @x-id "check" // @x-id "check"
// @Base /api/v1 // @Base /api/v1
// @Summary Check authentication status // @Summary Check authentication status
// @Description Checks if the user is authenticated by validating their token // @Description Checks if the user is authenticated by validating their token
// @Tags auth // @Tags auth
// @Produce plain // @Produce plain
// @Success 200 {string} string "OK" // @Success 200 {string} string "OK"
// @Failure 403 {string} string "Forbidden: use X-Redirect-To header to redirect to login page" // @Failure 302 {string} string "Redirects to login page or IdP"
// @Router /auth/check [head] // @Router /auth/check [head]
func Check(c *gin.Context) { func Check(c *gin.Context) {
auth.AuthCheckHandler(c.Writer, c.Request) auth.AuthCheckHandler(c.Writer, c.Request)

View File

@@ -12,7 +12,6 @@ import (
// @Tags auth // @Tags auth
// @Produce plain // @Produce plain
// @Success 302 {string} string "Redirects to login page or IdP" // @Success 302 {string} string "Redirects to login page or IdP"
// @Failure 403 {string} string "Forbidden(webui): follow X-Redirect-To header"
// @Failure 429 {string} string "Too Many Requests" // @Failure 429 {string} string "Too Many Requests"
// @Router /auth/login [post] // @Router /auth/login [post]
func Login(c *gin.Context) { func Login(c *gin.Context) {

View File

@@ -239,8 +239,8 @@
"type": "string" "type": "string"
} }
}, },
"403": { "302": {
"description": "Forbidden: use X-Redirect-To header to redirect to login page", "description": "Redirects to login page or IdP",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@@ -267,12 +267,6 @@
"type": "string" "type": "string"
} }
}, },
"403": {
"description": "Forbidden(webui): follow X-Redirect-To header",
"schema": {
"type": "string"
}
},
"429": { "429": {
"description": "Too Many Requests", "description": "Too Many Requests",
"schema": { "schema": {

View File

@@ -1581,8 +1581,8 @@ paths:
description: OK description: OK
schema: schema:
type: string type: string
"403": "302":
description: 'Forbidden: use X-Redirect-To header to redirect to login page' description: Redirects to login page or IdP
schema: schema:
type: string type: string
summary: Check authentication status summary: Check authentication status
@@ -1600,10 +1600,6 @@ paths:
description: Redirects to login page or IdP description: Redirects to login page or IdP
schema: schema:
type: string type: string
"403":
description: 'Forbidden(webui): follow X-Redirect-To header'
schema:
type: string
"429": "429":
description: Too Many Requests description: Too Many Requests
schema: schema:

View File

@@ -129,8 +129,7 @@ func (auth *UserPassAuth) PostAuthCallbackHandler(w http.ResponseWriter, r *http
} }
func (auth *UserPassAuth) LoginHandler(w http.ResponseWriter, r *http.Request) { func (auth *UserPassAuth) LoginHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Redirect-To", "/login") http.Redirect(w, r, "/login", http.StatusFound)
w.WriteHeader(http.StatusForbidden)
} }
func (auth *UserPassAuth) LogoutHandler(w http.ResponseWriter, r *http.Request) { func (auth *UserPassAuth) LogoutHandler(w http.ResponseWriter, r *http.Request) {