fix: make file correcrt repo

This commit is contained in:
王性驊 2025-03-12 18:51:02 +08:00
parent 23d0ce66e9
commit 8a746d9b40
5 changed files with 83 additions and 2 deletions

View File

@ -121,6 +121,17 @@ message Tokens{
repeated TokenResp token = 1;
}
message GetSystemClaimReq{
string access_token=1;
bool is_expired=2;
}
message GetSystemClaimResp {
map<string,string> data = 1;
}
// Token
// Biz GW
// access_token -> token , refresh_token -> one_time_token
@ -141,6 +152,8 @@ service TokenService {
rpc GetUserTokensByDeviceID(DoTokenByDeviceIDReq) returns(Tokens);
// GetUserTokensByUID UID Tokens
rpc GetUserTokensByUID(QueryTokenByUIDReq) returns(Tokens);
// Claim
rpc GetSystemClaimByAccessToken(GetSystemClaimReq) returns(GetSystemClaimResp);
}

View File

@ -0,0 +1,36 @@
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"
"github.com/zeromicro/go-zero/core/logx"
)
type GetSystemClaimByAccessTokenLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetSystemClaimByAccessTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSystemClaimByAccessTokenLogic {
return &GetSystemClaimByAccessTokenLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetSystemClaimByAccessToken 取得 Claim
func (l *GetSystemClaimByAccessTokenLogic) GetSystemClaimByAccessToken(in *permission.GetSystemClaimReq) (*permission.GetSystemClaimResp, error) {
claim, err := l.svcCtx.TokenUseCase.ParseSystemClaimsByAccessToken(in.GetAccessToken(), l.svcCtx.Config.Token.Secret, in.GetIsExpired())
if err != nil {
return nil, err
}
return &permission.GetSystemClaimResp{
Data: claim,
}, nil
}

View File

@ -0,0 +1,22 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.8.1
// Source: permission.proto
package server
import (
"code.30cm.net/digimon/app-cloudep-permission-server/gen_result/pb/permission"
"code.30cm.net/digimon/app-cloudep-permission-server/internal/logic/permissionservice"
"code.30cm.net/digimon/app-cloudep-permission-server/internal/svc"
)
type PermissionServiceServer struct {
svcCtx *svc.ServiceContext
permission.UnimplementedPermissionServiceServer
}
func NewPermissionServiceServer(svcCtx *svc.ServiceContext) *PermissionServiceServer {
return &PermissionServiceServer{
svcCtx: svcCtx,
}
}

View File

@ -1,5 +1,5 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.3
// goctl 1.8.1
// Source: permission.proto
package server
@ -70,3 +70,9 @@ func (s *TokenServiceServer) GetUserTokensByUID(ctx context.Context, in *permiss
l := tokenservicelogic.NewGetUserTokensByUIDLogic(ctx, s.svcCtx)
return l.GetUserTokensByUID(in)
}
// 取得 Claim
func (s *TokenServiceServer) GetSystemClaimByAccessToken(ctx context.Context, in *permission.GetSystemClaimReq) (*permission.GetSystemClaimResp, error) {
l := tokenservicelogic.NewGetSystemClaimByAccessTokenLogic(ctx, s.svcCtx)
return l.GetSystemClaimByAccessToken(in)
}

View File

@ -450,8 +450,12 @@ func (use *TokenUseCase) newToken(ctx context.Context, req *usecase.GenerateToke
RefreshCreateAt: now.UnixNano(),
UID: req.UID,
}
initData := make(map[string]string, 0)
for k, v := range req.Data {
initData[k] = v
}
// 故意 data 裡面不會有那些已經有的欄位資訊
data := NewAdditional(req.Data)
data := NewAdditional(initData)
data.Set(dt.ID, token.ID)
data.Set(dt.Role, req.Role)
data.Set(dt.Scope, req.Scope)