659168fe32
- Implemented authz-adapter deployment and service for Envoy gRPC authorization. - Created PowerShell script to generate JWK for JWT authentication. - Documented the integration of ext_authz with user-rpc.ValidateToken in ENVOY_EXT_AUTHZ_ADAPTER.md. - Added comprehensive Envoy Gateway configuration guide with JWT authentication and access control in ENVOY_GATEWAY_GUIDE.md.
46 lines
916 B
Go
46 lines
916 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"juwan-backend/app/users/rpc/internal/svc"
|
|
"juwan-backend/app/users/rpc/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
var USER_TOKEN_TEMP = "jwt:%v"
|
|
|
|
type ValidateTokenLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewValidateTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ValidateTokenLogic {
|
|
return &ValidateTokenLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *ValidateTokenLogic) ValidateToken(in *pb.ValidateTokenReq) (*pb.ValidateTokenResp, error) {
|
|
|
|
_, err := l.svcCtx.JwtManager.Valid(l.ctx, in.Token)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
users, err := l.svcCtx.UsersModelRO.FindOne(l.ctx, in.UserId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &pb.ValidateTokenResp{
|
|
Valid: true,
|
|
Message: "OK",
|
|
UserId: in.UserId,
|
|
RoleType: users.RoleType,
|
|
}, nil
|
|
}
|