feat: create new token ut

This commit is contained in:
daniel.w 2024-08-06 15:52:42 +08:00
parent d82e9e1a54
commit bb2459f751
2 changed files with 6 additions and 2 deletions

1
go.mod
View File

@ -9,6 +9,7 @@ require (
github.com/google/uuid v1.6.0
github.com/stretchr/testify v1.9.0
github.com/zeromicro/go-zero v1.7.0
go.uber.org/mock v0.4.0
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
)

View File

@ -42,6 +42,9 @@ type authorizationReq struct {
IsRefreshToken bool `json:"is_refresh_token"`
}
var generateAccessTokenFunc = generateAccessToken
var generateRefreshTokenFunc = generateRefreshToken
// NewToken 建立一個新的 Token例如AccessToken
func (l *NewTokenLogic) NewToken(in *permission.AuthorizationReq) (*permission.TokenResp, error) {
// 驗證所需
@ -87,13 +90,13 @@ func (l *NewTokenLogic) NewToken(in *permission.AuthorizationReq) (*permission.T
}
var err error
token.AccessToken, err = generateAccessToken(token, claims, l.svcCtx.Config.Token.Secret)
token.AccessToken, err = generateAccessTokenFunc(token, claims, l.svcCtx.Config.Token.Secret)
if err != nil {
return nil, ers.ArkInternal(fmt.Errorf("accessGenerate token error: %w", err).Error())
}
if in.GetIsRefreshToken() {
token.RefreshToken = generateRefreshToken(token.AccessToken)
token.RefreshToken = generateRefreshTokenFunc(token.AccessToken)
}
err = l.svcCtx.TokenRedisRepo.Create(l.ctx, token)