试读部分
0、转载 go-zero docker-compose 搭建课件服务(六):完善jwt鉴权和返回结构 0.1源码地址 https://github.com/liuyuede123/go-zero-courseware 1、用户服务登录接口生成jwt token user/api/etc/user.yaml中增加用于生成jwt的secret和过期时间 ...
Auth:
AccessSecret: 38f9c7af24ff11edb92900163e30ef81
AccessExpire: 86400
user/api/internal/config/config.go增加配置参数 ...
Auth struct {
AccessSecret string
AccessExpire int64
}
在之前编写的登录逻辑中增加获取token的方法,并修改登录逻辑 ...
func (l *UserLoginLogic) UserLogin(req *types.LoginRequest) (resp *types.LoginResponse, err error) {
login, err := l.svcCtx.UserRpc.Login(l.ctx, &userclient.LoginRequest{
LoginName: req.LoginName,
Password: req.Password,
})
if err != nil {
return nil, err
}
now := time.Now().Unix()
login.Token, err = l.getJwtToken(l.svcCtx.Config.Auth.AccessSecret, now, l.svcCtx.Config.Auth.AccessE……
本文为 VIP 文章,已展示部分内容,开通 VIP 后查看全文
觉得这篇文章有帮助?
点个赞,或赞赏支持作者持续创作