token

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MulanPSL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Service_IssueToken_FullMethodName    = "/keyauth.apps.token.Service/IssueToken"
	Service_QueryToken_FullMethodName    = "/keyauth.apps.token.Service/QueryToken"
	Service_ValidateToken_FullMethodName = "/keyauth.apps.token.Service/ValidateToken"
	Service_RevolkToken_FullMethodName   = "/keyauth.apps.token.Service/RevolkToken"
	Service_DescribeToken_FullMethodName = "/keyauth.apps.token.Service/DescribeToken"
)
View Source
const (
	AppName = "token"
)
View Source
const (
	DefaultDomain = "default"
)

Variables

View Source
var (
	GranteType_name = map[int32]string{
		0: "PASSWORD",
		1: "LADP",
		2: "OATH2",
		3: "ACCESS_TOKEN",
		4: "REFRESH_TOKEN",
	}
	GranteType_value = map[string]int32{
		"PASSWORD":      0,
		"LADP":          1,
		"OATH2":         2,
		"ACCESS_TOKEN":  3,
		"REFRESH_TOKEN": 4,
	}
)

Enum value maps for GranteType.

View Source
var (
	DefaultTokenDuration = 10 * time.Minute
)
View Source
var File_apps_token_pb_token_proto protoreflect.FileDescriptor
View Source
var Service_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "keyauth.apps.token.Service",
	HandlerType: (*ServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "IssueToken",
			Handler:    _Service_IssueToken_Handler,
		},
		{
			MethodName: "QueryToken",
			Handler:    _Service_QueryToken_Handler,
		},
		{
			MethodName: "ValidateToken",
			Handler:    _Service_ValidateToken_Handler,
		},
		{
			MethodName: "RevolkToken",
			Handler:    _Service_RevolkToken_Handler,
		},
		{
			MethodName: "DescribeToken",
			Handler:    _Service_DescribeToken_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "apps/token/pb/token.proto",
}

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

Functions

func RegisterServiceServer

func RegisterServiceServer(s grpc.ServiceRegistrar, srv ServiceServer)

Types

type DescribeTokenRequest

type DescribeTokenRequest struct {

	// token id
	// @gotags: json:"access_token"
	AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token"`
	// contains filtered or unexported fields
}

func NewDescribeTokenRequest

func NewDescribeTokenRequest(accessToken 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 GranteType

type GranteType int32
const (
	// 通过password授权
	GranteType_PASSWORD GranteType = 0
	// 通过LDAP
	GranteType_LADP GranteType = 1
	// OATH2
	GranteType_OATH2 GranteType = 2
	// 通过ACCESS_TOKEN来获取token,用于api用户访问(Restful SDK)
	// 通过一个User password 的token 来生成一个ACCESS TOKEN
	// HTTP API 编程访问
	GranteType_ACCESS_TOKEN GranteType = 3
	// 通过REFRESH_TOKEN获取令牌
	GranteType_REFRESH_TOKEN GranteType = 4
)

func ParseGranteTypeFromString

func ParseGranteTypeFromString(str string) (GranteType, error)

ParseGranteTypeFromString Parse GranteType from string

func (GranteType) Descriptor

func (GranteType) Descriptor() protoreflect.EnumDescriptor

func (GranteType) Enum

func (x GranteType) Enum() *GranteType

func (GranteType) EnumDescriptor deprecated

func (GranteType) EnumDescriptor() ([]byte, []int)

Deprecated: Use GranteType.Descriptor instead.

func (GranteType) Equal

func (t GranteType) Equal(target GranteType) bool

Equal type compare

func (GranteType) IsIn

func (t GranteType) IsIn(targets ...GranteType) bool

IsIn todo

func (GranteType) MarshalJSON

func (t GranteType) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (GranteType) Number

func (x GranteType) Number() protoreflect.EnumNumber

func (GranteType) String

func (x GranteType) String() string

func (GranteType) Type

func (*GranteType) UnmarshalJSON

func (t *GranteType) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type IssueTokenRequest

type IssueTokenRequest struct {

	// 授权类型
	// @gotags: json:"grante_type" bson:"grante_type"
	GranteType GranteType `` /* 136-byte string literal not displayed */
	// 用户名
	// @gotags: json:"username" bson:"username"
	Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username" bson:"username"`
	// 用户密码,不需要入库
	// @gotags: json:"password" bson:"-"
	Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password" bson:"-"`
	// domain
	// @gotags: json:"domain" bson:"domain"
	UserDomain string `protobuf:"bytes,4,opt,name=user_domain,json=userDomain,proto3" json:"domain" bson:"domain"`
	// 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) GetGranteType

func (x *IssueTokenRequest) GetGranteType() GranteType

func (*IssueTokenRequest) GetPassword

func (x *IssueTokenRequest) GetPassword() string

func (*IssueTokenRequest) GetUserDomain

func (x *IssueTokenRequest) GetUserDomain() 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

func (*IssueTokenRequest) Validate

func (req *IssueTokenRequest) Validate() error

type QueryTokenRequest

type QueryTokenRequest struct {

	// 分页参数
	// @gotags: json:"page"
	Page *page.PageRequest `protobuf:"bytes,1,opt,name=page,proto3" json:"page"`
	// 关键字参数
	// @gotags: json:"keywords"
	Keywords string `protobuf:"bytes,2,opt,name=keywords,proto3" json:"keywords"`
	// contains filtered or unexported fields
}

func NewQueryTokenRequestFromHTTP

func NewQueryTokenRequestFromHTTP(r *http.Request) *QueryTokenRequest

func (*QueryTokenRequest) Descriptor deprecated

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

Deprecated: Use QueryTokenRequest.ProtoReflect.Descriptor instead.

func (*QueryTokenRequest) GetKeywords

func (x *QueryTokenRequest) GetKeywords() string

func (*QueryTokenRequest) GetPage

func (x *QueryTokenRequest) GetPage() *page.PageRequest

func (*QueryTokenRequest) ProtoMessage

func (*QueryTokenRequest) ProtoMessage()

func (*QueryTokenRequest) ProtoReflect

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

func (*QueryTokenRequest) Reset

func (x *QueryTokenRequest) Reset()

func (*QueryTokenRequest) String

func (x *QueryTokenRequest) String() string

type RevolkTokenRequest

type RevolkTokenRequest struct {

	// token id
	// @gotags: json:"access_token"
	AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token"`
	// refresh 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"`
	// contains filtered or unexported fields
}

func NewRevolkTokenRequest

func NewRevolkTokenRequest() *RevolkTokenRequest

func NewRevolkTokenRequestWithID

func NewRevolkTokenRequestWithID(id string) *RevolkTokenRequest

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 ServiceClient

type ServiceClient interface {
	// 颁发token
	IssueToken(ctx context.Context, in *IssueTokenRequest, opts ...grpc.CallOption) (*Token, error)
	// 查询用户颁发的access_token,特指restful api访问颁发出去的token
	QueryToken(ctx context.Context, in *QueryTokenRequest, opts ...grpc.CallOption) (*TokenSet, error)
	// 校验token的接口(内部服务使用)
	ValidateToken(ctx context.Context, in *ValidateTokenRequest, opts ...grpc.CallOption) (*Token, error)
	// 撤销token(注销)
	RevolkToken(ctx context.Context, in *RevolkTokenRequest, opts ...grpc.CallOption) (*Token, error)
	DescribeToken(ctx context.Context, in *DescribeTokenRequest, opts ...grpc.CallOption) (*Token, error)
}

ServiceClient is the client API for Service 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 NewServiceClient

func NewServiceClient(cc grpc.ClientConnInterface) ServiceClient

type ServiceServer

type ServiceServer interface {
	// 颁发token
	IssueToken(context.Context, *IssueTokenRequest) (*Token, error)
	// 查询用户颁发的access_token,特指restful api访问颁发出去的token
	QueryToken(context.Context, *QueryTokenRequest) (*TokenSet, error)
	// 校验token的接口(内部服务使用)
	ValidateToken(context.Context, *ValidateTokenRequest) (*Token, error)
	// 撤销token(注销)
	RevolkToken(context.Context, *RevolkTokenRequest) (*Token, error)
	DescribeToken(context.Context, *DescribeTokenRequest) (*Token, error)
	// contains filtered or unexported methods
}

ServiceServer is the server API for Service service. All implementations must embed UnimplementedServiceServer for forward compatibility

type Token

type Token struct {

	// 唯一ID
	//
	//	注意这里存名为"_id" 的原因是因为主键只能是这样写,mongodb 的默认主键就是"_id"
	//
	// @gotags: json:"access_token" bson:"_id"
	AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token" bson:"_id"`
	// 录入时间
	// @inject_tag: json:"issue_at" bson:"issue_at"
	IssueAt int64 `protobuf:"varint,2,opt,name=issue_at,json=issueAt,proto3" json:"issue_at" bson:"issue_at"`
	// 更新时间
	// @gotags: json:"update_at" bson:"update_at"
	UpdateAt int64 `protobuf:"varint,3,opt,name=update_at,json=updateAt,proto3" json:"update_at" bson:"update_at"`
	// 更新人
	// @gotags: json:"update_by" bson:"update_by"
	UpdateBy string `protobuf:"bytes,4,opt,name=update_by,json=updateBy,proto3" json:"update_by" bson:"update_by"`
	// token颁发请求
	// @gotags: json:"data" bson:"data"
	Data *IssueTokenRequest `protobuf:"bytes,5,opt,name=data,proto3" json:"data" bson:"data"`
	// Access Token 过期时间(绝对时间),10分钟的话就是,now() + 10分钟
	// @gotags: json:"access_token_expired_at" bson:"access_token_expired_at"
	AccessTokenExpiredAt int64 `` /* 147-byte string literal not displayed */
	//	token过期了,允许刷新
	//
	// @gotags: json:"refresh_token" bson:"refresh_token"
	RefreshToken string `protobuf:"bytes,7,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token" bson:"refresh_token"`
	//	refresh_token的过期时间
	//
	// @gotags: json:"refresh_token_expired_at" bson:"refresh_token_expired_at"
	RefreshTokenExpiredAt int64 `` /* 151-byte string literal not displayed */
	// 额外的信息,非必选
	//
	//	@gotags: json:"meta" bson:"meta"
	Meta map[string]string `` /* 151-byte string literal not displayed */
	// contains filtered or unexported fields
}

Token todo

func NewDefaultToken

func NewDefaultToken() *Token

func NewToken

func NewToken(req *IssueTokenRequest, expireDuration time.Duration) (*Token, error)

func (*Token) Descriptor deprecated

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

Deprecated: Use Token.ProtoReflect.Descriptor instead.

func (*Token) Extend

func (t *Token) Extend(expiredDuration time.Duration)

续约token , 延长一个生命周期

func (*Token) GetAccessToken

func (x *Token) GetAccessToken() string

func (*Token) GetAccessTokenExpiredAt

func (x *Token) GetAccessTokenExpiredAt() int64

func (*Token) GetData

func (x *Token) GetData() *IssueTokenRequest

func (*Token) GetIssueAt

func (x *Token) GetIssueAt() int64

func (*Token) GetMeta

func (x *Token) GetMeta() map[string]string

func (*Token) GetRefreshToken

func (x *Token) GetRefreshToken() string

func (*Token) GetRefreshTokenExpiredAt

func (x *Token) GetRefreshTokenExpiredAt() int64

func (*Token) GetUpdateAt

func (x *Token) GetUpdateAt() int64

func (*Token) GetUpdateBy

func (x *Token) GetUpdateBy() string

func (*Token) IsRefreshTokenExpired

func (t *Token) IsRefreshTokenExpired() bool

func (*Token) ProtoMessage

func (*Token) ProtoMessage()

func (*Token) ProtoReflect

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

func (*Token) Reset

func (x *Token) Reset()

func (*Token) String

func (x *Token) String() string

func (*Token) Validate

func (t *Token) Validate() error

type TokenSet

type TokenSet struct {

	// 分页时,返回总数量
	// @gotags: json:"total"
	Total int64 `protobuf:"varint,1,opt,name=total,proto3" json:"total"`
	// 一页的数据
	// @gotags: json:"items"
	Items []*Token `protobuf:"bytes,2,rep,name=items,proto3" json:"items"`
	// contains filtered or unexported fields
}

TokenSet todo

func NewTokenSet

func NewTokenSet() *TokenSet

func (*TokenSet) Add

func (set *TokenSet) Add(token *Token)

func (*TokenSet) Descriptor deprecated

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

Deprecated: Use TokenSet.ProtoReflect.Descriptor instead.

func (*TokenSet) GetItems

func (x *TokenSet) GetItems() []*Token

func (*TokenSet) GetTotal

func (x *TokenSet) GetTotal() int64

func (*TokenSet) ProtoMessage

func (*TokenSet) ProtoMessage()

func (*TokenSet) ProtoReflect

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

func (*TokenSet) Reset

func (x *TokenSet) Reset()

func (*TokenSet) String

func (x *TokenSet) String() string

type UnimplementedServiceServer

type UnimplementedServiceServer struct {
}

UnimplementedServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedServiceServer) DescribeToken

func (UnimplementedServiceServer) IssueToken

func (UnimplementedServiceServer) QueryToken

func (UnimplementedServiceServer) RevolkToken

func (UnimplementedServiceServer) ValidateToken

type UnsafeServiceServer

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

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

type ValidateTokenRequest

type ValidateTokenRequest struct {

	// token id
	// @gotags: json:"access_token"
	AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token"`
	// contains filtered or unexported fields
}

func NewValidateTokenRequest

func NewValidateTokenRequest(accessToken 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