Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 31s
refactor(api/user): 重构用户相关接口使用token验证替代user_id路径参数 docs: 更新API文档规范,明确私有接口需携带token及返回字段要求 fix(service/user): 避免写入未使用字段的零值导致MySQL校验错误 style: 统一格式化部分代码缩进和导入顺序 chore: 更新DS_Store等IDE配置文件
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package interceptor
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"bindbox-game/configs"
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
"bindbox-game/internal/pkg/jwtoken"
|
|
"bindbox-game/internal/proposal"
|
|
)
|
|
|
|
func (i *interceptor) AppTokenAuthVerify(ctx core.Context) (sessionUserInfo proposal.SessionUserInfo, err core.BusinessError) {
|
|
headerAuthorizationString := ctx.GetHeader("Authorization")
|
|
if headerAuthorizationString == "" {
|
|
err = core.Error(
|
|
http.StatusUnauthorized,
|
|
code.JWTAuthVerifyError,
|
|
"无法确认您的身份,请进行登录。",
|
|
)
|
|
return
|
|
}
|
|
|
|
jwtClaims, jwtErr := jwtoken.New(configs.Get().JWT.PatientSecret).Parse(headerAuthorizationString)
|
|
if jwtErr != nil {
|
|
err = core.Error(
|
|
http.StatusUnauthorized,
|
|
code.JWTAuthVerifyError,
|
|
"您的账号登录过期,请重新登录。",
|
|
)
|
|
return
|
|
}
|
|
|
|
sessionUserInfo = jwtClaims.SessionUserInfo
|
|
return
|
|
} |