feat(app): 添加 token 校验功能和用户信息获取接口
- 新增 AuthToken 方法用于校验用户 token - 在 app 接口中添加 AuthToken 方法定义 - 在 defaultApp 结构体中实现 AuthToken 方法 - 修改 GetVerifyCode、Login、Register 接口的 tags 为 user_public - 新增 /user POST 接口用于获取用户详细信息 - 在 app.pb.go 文件中新增 AuthInfoResp、AuthReq 等相关结构体定义 - 更新 proto 文件中的消息类型索引以适应新增结构体 - 新增 ClaimStrings 和 NumericDate 结构体支持 JWT 相关字段 - 新增 RegisteredClaims 结构体用于表示 JWT 声明集
This commit is contained in:
parent
225cf2d135
commit
00a2ca670d
|
|
@ -55,13 +55,6 @@ func writeError(w http.ResponseWriter, statusCode int, message string) {
|
|||
func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
startTime := time.Now()
|
||||
|
||||
// 检查是否为公开路径(可选)
|
||||
if m.isPublicPath(r.URL.Path) {
|
||||
next(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// 1. 从 Authorization Header 中提取 Bearer Token
|
||||
authHeader := r.Header.Get("Authorization")
|
||||
if authHeader == "" {
|
||||
|
|
@ -149,21 +142,3 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
|||
next(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
// isPublicPath 检查是否为公开路径
|
||||
func (m *AuthorityMiddleware) isPublicPath(path string) bool {
|
||||
publicPaths := []string{
|
||||
"/api/login",
|
||||
"/api/register",
|
||||
"/api/public/",
|
||||
"/health",
|
||||
"/metrics",
|
||||
}
|
||||
|
||||
for _, publicPath := range publicPaths {
|
||||
if strings.HasPrefix(path, publicPath) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue