Documentation
¶
Index ¶
- func AuthorizationContext(ctx context.Context, token string) context.Context
- func AuthorizationMetadata(token string) metadata.MD
- type RefreshState
- type RefreshStats
- type RefreshStrategy
- type ServiceAuthHelper
- func (h *ServiceAuthHelper) CallWithAuth(ctx context.Context, fn func(ctx context.Context) error) error
- func (h *ServiceAuthHelper) GetToken(ctx context.Context) (string, error)
- func (h *ServiceAuthHelper) NewAuthenticatedContext(ctx context.Context) (context.Context, error)
- func (h *ServiceAuthHelper) State() RefreshState
- func (h *ServiceAuthHelper) Stats() RefreshStats
- func (h *ServiceAuthHelper) Stop()
- type ServiceAuthOption
- type ServiceTokenIssuer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthorizationContext ¶
AuthorizationContext 创建带 Authorization 头的 Context。
func AuthorizationMetadata ¶
AuthorizationMetadata 返回包含 Authorization 的 metadata。
Types ¶
type RefreshState ¶
type RefreshState int32
RefreshState 刷新状态。
const ( RefreshStateNormal RefreshState = iota RefreshStateRetrying RefreshStateCircuitOpen )
func (RefreshState) String ¶
func (s RefreshState) String() string
type RefreshStats ¶
type RefreshStats struct {
TotalRefreshes int64
SuccessfulRefreshes int64
FailedRefreshes int64
ConsecutiveFailures int64
LastRefreshTime time.Time
LastRefreshError error
State RefreshState
}
RefreshStats 刷新统计。
type RefreshStrategy ¶
type RefreshStrategy struct {
JitterRatio float64
MinBackoff time.Duration
MaxBackoff time.Duration
BackoffMultiplier float64
MaxRetries int
CircuitOpenDuration time.Duration
OnRefreshSuccess func(token string, expiresIn time.Duration)
OnRefreshFailure func(err error, attempt int, nextRetry time.Duration)
OnCircuitOpen func()
OnCircuitClose func()
}
RefreshStrategy 刷新策略配置。
func DefaultRefreshStrategy ¶
func DefaultRefreshStrategy() *RefreshStrategy
DefaultRefreshStrategy 默认刷新策略。
type ServiceAuthHelper ¶
type ServiceAuthHelper struct {
// contains filtered or unexported fields
}
ServiceAuthHelper 服务间认证助手。
func NewServiceAuthHelper ¶
func NewServiceAuthHelper(cfg *config.ServiceAuthConfig, authClient ServiceTokenIssuer, opts ...ServiceAuthOption) (*ServiceAuthHelper, error)
NewServiceAuthHelper 创建服务认证助手。
func NewServiceAuthHelperWithCallbacks ¶
func NewServiceAuthHelperWithCallbacks( cfg *config.ServiceAuthConfig, authClient ServiceTokenIssuer, onSuccess func(token string, expiresIn time.Duration), onFailure func(err error, attempt int, nextRetry time.Duration), ) (*ServiceAuthHelper, error)
NewServiceAuthHelperWithCallbacks 创建带回调的服务认证助手。
func (*ServiceAuthHelper) CallWithAuth ¶
func (h *ServiceAuthHelper) CallWithAuth(ctx context.Context, fn func(ctx context.Context) error) error
CallWithAuth 使用认证信息执行调用。
func (*ServiceAuthHelper) GetToken ¶
func (h *ServiceAuthHelper) GetToken(ctx context.Context) (string, error)
GetToken 获取当前有效的服务 Token。
func (*ServiceAuthHelper) NewAuthenticatedContext ¶
NewAuthenticatedContext 创建带认证信息的 Context。
type ServiceAuthOption ¶
type ServiceAuthOption func(*ServiceAuthHelper)
ServiceAuthOption 配置选项。
func WithRefreshStrategy ¶
func WithRefreshStrategy(strategy *RefreshStrategy) ServiceAuthOption
WithRefreshStrategy 设置刷新策略。
type ServiceTokenIssuer ¶
type ServiceTokenIssuer interface {
IssueServiceToken(context.Context, *authnv1.IssueServiceTokenRequest) (*authnv1.IssueServiceTokenResponse, error)
}
ServiceTokenIssuer 定义服务间认证所需的最小签发能力。
Click to show internal directories.
Click to hide internal directories.