feat/create_new_token #2

Merged
daniel.w merged 10 commits from feat/create_new_token into main 2024-08-12 14:20:15 +00:00
2 changed files with 6 additions and 2 deletions
Showing only changes of commit bb2459f751 - Show all commits

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)