feat: create new token ut
This commit is contained in:
parent
d82e9e1a54
commit
bb2459f751
1
go.mod
1
go.mod
|
@ -9,6 +9,7 @@ require (
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
github.com/zeromicro/go-zero v1.7.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/grpc v1.65.0
|
||||||
google.golang.org/protobuf v1.34.2
|
google.golang.org/protobuf v1.34.2
|
||||||
)
|
)
|
||||||
|
|
|
@ -42,6 +42,9 @@ type authorizationReq struct {
|
||||||
IsRefreshToken bool `json:"is_refresh_token"`
|
IsRefreshToken bool `json:"is_refresh_token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var generateAccessTokenFunc = generateAccessToken
|
||||||
|
var generateRefreshTokenFunc = generateRefreshToken
|
||||||
|
|
||||||
// NewToken 建立一個新的 Token,例如:AccessToken
|
// NewToken 建立一個新的 Token,例如:AccessToken
|
||||||
func (l *NewTokenLogic) NewToken(in *permission.AuthorizationReq) (*permission.TokenResp, error) {
|
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
|
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 {
|
if err != nil {
|
||||||
return nil, ers.ArkInternal(fmt.Errorf("accessGenerate token error: %w", err).Error())
|
return nil, ers.ArkInternal(fmt.Errorf("accessGenerate token error: %w", err).Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if in.GetIsRefreshToken() {
|
if in.GetIsRefreshToken() {
|
||||||
token.RefreshToken = generateRefreshToken(token.AccessToken)
|
token.RefreshToken = generateRefreshTokenFunc(token.AccessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = l.svcCtx.TokenRedisRepo.Create(l.ctx, token)
|
err = l.svcCtx.TokenRedisRepo.Create(l.ctx, token)
|
||||||
|
|
Loading…
Reference in New Issue