51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package tokenservicelogic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.30cm.net/digimon/app-cloudep-permission-server/gen_result/pb/permission"
|
|
"code.30cm.net/digimon/app-cloudep-permission-server/internal/svc"
|
|
"code.30cm.net/digimon/app-cloudep-permission-server/pkg/domain/usecase"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ValidationTokenLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewValidationTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ValidationTokenLogic {
|
|
return &ValidationTokenLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// ValidationToken 驗證這個 Token 有沒有效
|
|
func (l *ValidationTokenLogic) ValidationToken(in *permission.ValidationTokenReq) (*permission.ValidationTokenResp, error) {
|
|
token, err := l.svcCtx.TokenUseCase.VerifyToken(l.ctx, usecase.TokenRequest{
|
|
Token: in.GetToken(),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &permission.ValidationTokenResp{
|
|
Token: &permission.Token{
|
|
Id: token.Token.ID,
|
|
ClientId: 1,
|
|
DeviceId: token.Token.DeviceID,
|
|
AccessToken: token.Token.AccessToken,
|
|
ExpiresIn: token.Token.ExpiresIn,
|
|
AccessCreateAt: token.Token.AccessCreateAt,
|
|
RefreshToken: token.Token.RefreshToken,
|
|
RefreshExpiresIn: token.Token.RefreshExpiresIn,
|
|
RefreshCreateAt: token.Token.RefreshCreateAt,
|
|
},
|
|
Data: token.Data,
|
|
}, nil
|
|
}
|