fix(middleware): JWT 密钥未配置时返回 500 而非 401
密钥未配置属服务端配置错误,此前与 token 过期一样返回 401,把排查方向引向前端与刷新逻辑,是 P0-1 难以定位的直接原因。 改为识别 ErrSecretNotConfigured 后返回 500 server auth misconfigured 并打 FATAL 日志;JWTAuth、SoftJWTAuth 与 SSE 鉴权三处同步。
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -90,6 +91,13 @@ func (h *SSEHub) SSERequireAuth() gin.HandlerFunc {
|
||||
}
|
||||
claims, err := auth.ParseToken(token)
|
||||
if err != nil {
|
||||
// 与 middleware/jwt 保持一致:密钥未配置属服务端故障(500),不是客户端凭证问题。
|
||||
if errors.Is(err, auth.ErrSecretNotConfigured) {
|
||||
log.Printf("FATAL: JWT secret not configured; SSE %s rejected", c.Request.URL.Path)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError,
|
||||
gin.H{"error": "server auth misconfigured"})
|
||||
return
|
||||
}
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user