course/starbook/session-get-user-info #114
Replies: 6 comments 3 replies
-
这个少步骤了,缺少account_new.go文件,和star/internal/controller/account |
Beta Was this translation helpful? Give feedback.
-
为什么我这个g.RequestFromCtx(ctx).Request 为 nil 和上面代码一致 |
Beta Was this translation helpful? Give feedback.
-
jwtKey = utility.JwtKey |
Beta Was this translation helpful? Give feedback.
-
token signature is invalid: key is of invalid type: HMAC verify expects []byte |
Beta Was this translation helpful? Give feedback.
-
这句代码需要调整一下: token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
return jwtKey, nil
}) 改成: token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
return []byte(jwtKey), nil
}) |
Beta Was this translation helpful? Give feedback.
-
internal/logic/middleware/auth.go package middleware import (
) func Auth(r *ghttp.Request) { /internal/logic/users/users_account.go 这个文件里面的代码consts.JwtKey 应该改成 切片的形式如:[]byte(consts.JwtKey) import (
) type jwtClaims struct { func (u *Users) Login(ctx context.Context, username, password string) (tokenString string, err error) {
} func (u *Users) Info(ctx context.Context) (user *entity.Users, err error) {
} |
Beta Was this translation helpful? Give feedback.
-
course/starbook/session-get-user-info
用户信息接口需要登录后才能访问,并通过中间件统一验证Token的有效性。GoFrame框架提供了灵活的中间件机制,支持请求前后操作。通过Auth中间件验证HTTP请求中的Token,在Logic中解析Token获取用户信息,并通过定义Api和Controller调用控制器进行接口注册,实现用户信息接口的访问控制和权限认证。
https://goframe.org/course/starbook/session-get-user-info
Beta Was this translation helpful? Give feedback.
All reactions