token

package
v0.0.0-...-f4276bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 12 Imported by: 2

README

Token业务逻辑

Documentation

Index

Constants

View Source
const (
	HeaderAuthKey = "Authorization"
	CookieAuthKey = "mcenter_mini_token"
)

客户端常量

View Source
const (
	Rpc_IssueToken_FullMethodName    = "/go11.devcloud_mini.token.Rpc/IssueToken"
	Rpc_ValidateToken_FullMethodName = "/go11.devcloud_mini.token.Rpc/ValidateToken"
	Rpc_DesribeToken_FullMethodName  = "/go11.devcloud_mini.token.Rpc/DesribeToken"
)
View Source
const (
	AppName = "token"
)
View Source
const (
	CONTEXT_ATTRIBUTE_KEY = "token"
)

服务端常量

Variables

View Source
var File_mcenter_apps_token_pb_model_proto protoreflect.FileDescriptor
View Source
var File_mcenter_apps_token_pb_rpc_proto protoreflect.FileDescriptor
View Source
var Rpc_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "go11.devcloud_mini.token.Rpc",
	HandlerType: (*RpcServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "IssueToken",
			Handler:    _Rpc_IssueToken_Handler,
		},
		{
			MethodName: "ValidateToken",
			Handler:    _Rpc_ValidateToken_Handler,
		},
		{
			MethodName: "DesribeToken",
			Handler:    _Rpc_DesribeToken_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "mcenter/apps/token/pb/rpc.proto",
}

Rpc_ServiceDesc is the grpc.ServiceDesc for Rpc service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func RegisterRpcServer

func RegisterRpcServer(s grpc.ServiceRegistrar, srv RpcServer)

Types

type DescribeTokenRequest

type DescribeTokenRequest struct {

	// 需要被撤销的Token
	AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
	// contains filtered or unexported fields
}

func NewDescribeTokenRequest

func NewDescribeTokenRequest(ak string) *DescribeTokenRequest

func (*DescribeTokenRequest) Descriptor deprecated

func (*DescribeTokenRequest) Descriptor() ([]byte, []int)

Deprecated: Use DescribeTokenRequest.ProtoReflect.Descriptor instead.

func (*DescribeTokenRequest) GetAccessToken

func (x *DescribeTokenRequest) GetAccessToken() string

func (*DescribeTokenRequest) ProtoMessage

func (*DescribeTokenRequest) ProtoMessage()

func (*DescribeTokenRequest) ProtoReflect

func (x *DescribeTokenRequest) ProtoReflect() protoreflect.Message

func (*DescribeTokenRequest) Reset

func (x *DescribeTokenRequest) Reset()

func (*DescribeTokenRequest) String

func (x *DescribeTokenRequest) String() string

type IssueTokenRequest

type IssueTokenRequest struct {

	// 用户名称
	Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
	// 密码
	Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"`
	// contains filtered or unexported fields
}

func NewIssueTokenRequest

func NewIssueTokenRequest() *IssueTokenRequest

func (*IssueTokenRequest) Descriptor deprecated

func (*IssueTokenRequest) Descriptor() ([]byte, []int)

Deprecated: Use IssueTokenRequest.ProtoReflect.Descriptor instead.

func (*IssueTokenRequest) GetPassword

func (x *IssueTokenRequest) GetPassword() string

func (*IssueTokenRequest) GetUsername

func (x *IssueTokenRequest) GetUsername() string

func (*IssueTokenRequest) ProtoMessage

func (*IssueTokenRequest) ProtoMessage()

func (*IssueTokenRequest) ProtoReflect

func (x *IssueTokenRequest) ProtoReflect() protoreflect.Message

func (*IssueTokenRequest) Reset

func (x *IssueTokenRequest) Reset()

func (*IssueTokenRequest) String

func (x *IssueTokenRequest) String() string

type RevolkTokenRequest

type RevolkTokenRequest struct {

	// 需要被撤销的Token
	AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
	// 使用Refresh Token做撤销验证
	RefreshToken string `protobuf:"bytes,2,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"`
	// contains filtered or unexported fields
}

func (*RevolkTokenRequest) Descriptor deprecated

func (*RevolkTokenRequest) Descriptor() ([]byte, []int)

Deprecated: Use RevolkTokenRequest.ProtoReflect.Descriptor instead.

func (*RevolkTokenRequest) GetAccessToken

func (x *RevolkTokenRequest) GetAccessToken() string

func (*RevolkTokenRequest) GetRefreshToken

func (x *RevolkTokenRequest) GetRefreshToken() string

func (*RevolkTokenRequest) ProtoMessage

func (*RevolkTokenRequest) ProtoMessage()

func (*RevolkTokenRequest) ProtoReflect

func (x *RevolkTokenRequest) ProtoReflect() protoreflect.Message

func (*RevolkTokenRequest) Reset

func (x *RevolkTokenRequest) Reset()

func (*RevolkTokenRequest) String

func (x *RevolkTokenRequest) String() string

type RpcClient

type RpcClient interface {
	// 令牌颁发
	IssueToken(ctx context.Context, in *IssueTokenRequest, opts ...grpc.CallOption) (*Token, error)
	// 校验令牌, 给其他服务确认用户身份使用
	ValidateToken(ctx context.Context, in *ValidateTokenRequest, opts ...grpc.CallOption) (*Token, error)
	// 获取Token, 内部Debug使用
	DesribeToken(ctx context.Context, in *DescribeTokenRequest, opts ...grpc.CallOption) (*Token, error)
}

RpcClient is the client API for Rpc service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewRpcClient

func NewRpcClient(cc grpc.ClientConnInterface) RpcClient

type RpcServer

type RpcServer interface {
	// 令牌颁发
	IssueToken(context.Context, *IssueTokenRequest) (*Token, error)
	// 校验令牌, 给其他服务确认用户身份使用
	ValidateToken(context.Context, *ValidateTokenRequest) (*Token, error)
	// 获取Token, 内部Debug使用
	DesribeToken(context.Context, *DescribeTokenRequest) (*Token, error)
	// contains filtered or unexported methods
}

RpcServer is the server API for Rpc service. All implementations must embed UnimplementedRpcServer for forward compatibility

type Service

type Service interface {
	// 业务RPC接口实现约束
	RpcServer
	// 撤销
	RevolkToken(context.Context, *RevolkTokenRequest) (*Token, error)
}

type Token

type Token struct {

	// 访问令牌
	// @gotags: json:"access_token" bson:"access_token"
	AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token" bson:"access_token"`
	// 刷新Token
	// @gotags: json:"refresh_token" bson:"refresh_token"
	RefreshToken string `protobuf:"bytes,2,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token" bson:"refresh_token"`
	// 令牌颁发时间
	// @gotags: json:"issue_at" bson:"issue_at"
	IssueAt int64 `protobuf:"varint,3,opt,name=issue_at,json=issueAt,proto3" json:"issue_at" bson:"issue_at"`
	// 多少秒后过期
	// @gotags: json:"access_token_expired_second" bson:"access_token_expired_second"
	AccessTokenExpiredSecond int64 `` /* 163-byte string literal not displayed */
	// 多少秒后过期
	// @gotags: json:"refresh_token_expired_second" bson:"refresh_token_expired_second"
	RefreshTokenExpiredSecond int64 `` /* 167-byte string literal not displayed */
	// 颁发的用户
	// @gotags: json:"username" bson:"username"
	Username string `protobuf:"bytes,5,opt,name=username,proto3" json:"username" bson:"username"`
	// 用户的角色
	// @gotags: json:"roles" bson:"roles"
	Roles *role.RoleSet `protobuf:"bytes,7,opt,name=roles,proto3" json:"roles" bson:"roles"`
	// contains filtered or unexported fields
}

func NewToken

func NewToken() *Token

func (*Token) AcccessTokenExpiredTime

func (t *Token) AcccessTokenExpiredTime() time.Time

func (*Token) Descriptor deprecated

func (*Token) Descriptor() ([]byte, []int)

Deprecated: Use Token.ProtoReflect.Descriptor instead.

func (*Token) GetAccessToken

func (x *Token) GetAccessToken() string

func (*Token) GetAccessTokenExpiredSecond

func (x *Token) GetAccessTokenExpiredSecond() int64

func (*Token) GetIssueAt

func (x *Token) GetIssueAt() int64

func (*Token) GetRefreshToken

func (x *Token) GetRefreshToken() string

func (*Token) GetRefreshTokenExpiredSecond

func (x *Token) GetRefreshTokenExpiredSecond() int64

func (*Token) GetRoles

func (x *Token) GetRoles() *role.RoleSet

func (*Token) GetUsername

func (x *Token) GetUsername() string

func (*Token) HasPerm

func (t *Token) HasPerm(servce, secret, action string) error

用户对 服务(cmdb), 那个资源(secret)的 那个操作是否有权限(list)

func (*Token) IsAcccessTokenExpired

func (t *Token) IsAcccessTokenExpired() bool

判断ak是否过期

func (*Token) IsRefreshTokenExpired

func (t *Token) IsRefreshTokenExpired() bool

判断ak是否过期

func (*Token) IssueTime

func (t *Token) IssueTime() time.Time

func (*Token) ProtoMessage

func (*Token) ProtoMessage()

func (*Token) ProtoReflect

func (x *Token) ProtoReflect() protoreflect.Message

func (*Token) RefreshTokenExpiredTime

func (t *Token) RefreshTokenExpiredTime() time.Time

func (*Token) Reset

func (x *Token) Reset()

func (*Token) String

func (x *Token) String() string

type UnimplementedRpcServer

type UnimplementedRpcServer struct {
}

UnimplementedRpcServer must be embedded to have forward compatible implementations.

func (UnimplementedRpcServer) DesribeToken

func (UnimplementedRpcServer) IssueToken

func (UnimplementedRpcServer) ValidateToken

type UnsafeRpcServer

type UnsafeRpcServer interface {
	// contains filtered or unexported methods
}

UnsafeRpcServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to RpcServer will result in compilation errors.

type ValidateTokenRequest

type ValidateTokenRequest struct {

	// 需要被撤销的Token
	AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
	// contains filtered or unexported fields
}

func NewValidateTokenRequest

func NewValidateTokenRequest(tk string) *ValidateTokenRequest

func (*ValidateTokenRequest) Descriptor deprecated

func (*ValidateTokenRequest) Descriptor() ([]byte, []int)

Deprecated: Use ValidateTokenRequest.ProtoReflect.Descriptor instead.

func (*ValidateTokenRequest) GetAccessToken

func (x *ValidateTokenRequest) GetAccessToken() string

func (*ValidateTokenRequest) ProtoMessage

func (*ValidateTokenRequest) ProtoMessage()

func (*ValidateTokenRequest) ProtoReflect

func (x *ValidateTokenRequest) ProtoReflect() protoreflect.Message

func (*ValidateTokenRequest) Reset

func (x *ValidateTokenRequest) Reset()

func (*ValidateTokenRequest) String

func (x *ValidateTokenRequest) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL