53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package tokenservicelogic
|
|
|
|
import (
|
|
ers "code.30cm.net/digimon/library-go/errors"
|
|
"context"
|
|
|
|
"app-cloudep-permission-server/gen_result/pb/permission"
|
|
"app-cloudep-permission-server/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CancelTokensLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewCancelTokensLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelTokensLogic {
|
|
return &CancelTokensLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// CancelTokens 取消 Token 從UID 視角,以及 token id 視角出發, UID 登出,底下所有 Device ID 也要登出, Token ID 登出, 所有 UID + Device 都要登出
|
|
func (l *CancelTokensLogic) CancelTokens(in *permission.DoTokenByUIDReq) (*permission.OKResp, error) {
|
|
if in.GetUid() != "" {
|
|
err := l.svcCtx.TokenRedisRepo.DeleteAccessTokensByUID(l.ctx, in.GetUid())
|
|
if err != nil {
|
|
logx.WithCallerSkip(1).WithFields(
|
|
logx.Field("func", "TokenRedisRepo.DeleteAccessTokensByUID"),
|
|
logx.Field("uid", in.GetUid()),
|
|
).Error(err.Error())
|
|
return nil, ers.ResourceInsufficient(err.Error())
|
|
}
|
|
}
|
|
|
|
if len(in.GetIds()) > 0 {
|
|
err := l.svcCtx.TokenRedisRepo.DeleteAccessTokenByID(l.ctx, in.GetIds())
|
|
if err != nil {
|
|
logx.WithCallerSkip(1).WithFields(
|
|
logx.Field("func", "TokenRedisRepo.DeleteAccessTokenByID"),
|
|
logx.Field("ids", in.GetIds()),
|
|
).Error(err.Error())
|
|
return nil, ers.ResourceInsufficient(err.Error())
|
|
}
|
|
}
|
|
|
|
return &permission.OKResp{}, nil
|
|
}
|