authstate

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	IdentityChangedEventType = types.CasdoorIdentityChangedEventType
)

Variables

View Source
var (
	ErrAuthorityUnavailable = errors.New("认证撤销权威存储不可用")
	ErrIdentityRevoked      = errors.New("认证身份已失效")
	ErrGenerationChanged    = errors.New("认证身份世代已变更")
	ErrInvalidIdentity      = errors.New("认证身份无效")
	ErrInvalidEvent         = errors.New("Casdoor事件无效")
	ErrEventNotFound        = errors.New("Casdoor事件不存在")
)

Functions

func IdentityChangedSubject

func IdentityChangedSubject(service string) string

IdentityChangedSubject 返回服务专属的 Casdoor 身份控制主题。

Types

type ApplyResult

type ApplyResult struct {
	Applied          bool
	Generation       uint64
	ControlPublished bool
	State            State
}

ApplyResult 区分首次应用、重复/乱序事件及控制通知是否已发布。

type BadgerStore

type BadgerStore struct {
	// contains filtered or unexported fields
}

BadgerStore 是单节点模式的权威存储,也是共享模式的已确认快照与 Hook 重试存储。

func OpenBadgerStore

func OpenBadgerStore(path string) (*BadgerStore, error)

func (*BadgerStore) AckHook

func (s *BadgerStore) AckHook(ctx context.Context, id string) error

func (*BadgerStore) Apply

func (s *BadgerStore) Apply(ctx context.Context, event types.CasdoorEvent, retention time.Duration) (ApplyResult, error)

func (*BadgerStore) Close

func (s *BadgerStore) Close() error

func (*BadgerStore) ConfirmActive

func (s *BadgerStore) ConfirmActive(ctx context.Context, key IdentityKey, expectedGeneration uint64) (State, error)

func (*BadgerStore) Current

func (s *BadgerStore) Current(ctx context.Context, key IdentityKey) (State, error)

func (*BadgerStore) MarkControlPublished

func (s *BadgerStore) MarkControlPublished(ctx context.Context, event types.CasdoorEvent) error

func (*BadgerStore) MarkPendingHookReady

func (s *BadgerStore) MarkPendingHookReady(ctx context.Context, id string) error

func (*BadgerStore) PendingHooks

func (s *BadgerStore) PendingHooks(ctx context.Context, limit int) ([]PendingHook, error)

func (*BadgerStore) SavePendingHook

func (s *BadgerStore) SavePendingHook(ctx context.Context, hook PendingHook) error

func (*BadgerStore) SaveSnapshot

func (s *BadgerStore) SaveSnapshot(ctx context.Context, state State) error

type EventBridge

type EventBridge interface {
	Subscribe(string, event.Handler) (func(), error)
	SubscribeExternal(context.Context, string) (func(), error)
	Publish(context.Context, event.PublishRequest) error
}

type IdentityKey

type IdentityKey struct {
	Service  string         `json:"service"`
	AuthType types.AuthType `json:"auth_type"`
	Provider string         `json:"provider"`
	Subject  string         `json:"subject"`
}

IdentityKey 唯一标识某服务某认证域中的外部身份。

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 将权威撤销状态与本地已确认快照组合为请求授权边界。

func NewManager

func NewManager(service string, cfg config.AuthRevocationConfig, options ...Option) (*Manager, error)

func (*Manager) AckHook

func (m *Manager) AckHook(ctx context.Context, id string) error

func (*Manager) ApplyEvent

func (m *Manager) ApplyEvent(ctx context.Context, event types.CasdoorEvent, retention time.Duration) (ApplyResult, error)

func (*Manager) Authorize

func (m *Manager) Authorize(ctx context.Context, identity types.AuthIdentity) error

func (*Manager) BeginClose

func (m *Manager) BeginClose()

BeginClose 立即拒绝新认证并停止事件订阅,但保留存储到 ServiceContext 完成其他组件清理。

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) ConfirmActive

func (m *Manager) ConfirmActive(ctx context.Context, identity types.AuthIdentity, expectedGeneration uint64) (State, error)

func (*Manager) Current

func (m *Manager) Current(ctx context.Context, identity types.AuthIdentity) (State, error)

func (*Manager) MarkControlPublished

func (m *Manager) MarkControlPublished(ctx context.Context, event types.CasdoorEvent) error

func (*Manager) PendingHooks

func (m *Manager) PendingHooks(ctx context.Context, limit int) ([]PendingHook, error)

func (*Manager) ProcessEvent

func (m *Manager) ProcessEvent(ctx context.Context, value types.CasdoorEvent, retention time.Duration) (ApplyResult, error)

ProcessEvent 原子应用权威状态,并等待控制通知被事件桥接受后再返回。 内置 shared 桥使用瞬时广播;接受不等于各副本已处理,漏通知由权威检查补偿。

func (*Manager) SavePendingHook

func (m *Manager) SavePendingHook(ctx context.Context, hook PendingHook) error

type Option

type Option func(*managerOptions)

func WithCasdoorEventHook

func WithCasdoorEventHook(hook types.ICasdoorEventHookProvider) Option

WithCasdoorEventHook 为 Manager 配置持久化重试的业务事件 Hook。

func WithEventBridge

func WithEventBridge(bridge EventBridge) Option

WithEventBridge 为撤销 Manager 绑定 ServiceContext 专属的本地/外部事件桥。

type PendingHook

type PendingHook struct {
	ID          string             `json:"id"`
	Event       types.CasdoorEvent `json:"event"`
	Ready       bool               `json:"ready"`
	Attempts    int                `json:"attempts"`
	NextAttempt time.Time          `json:"next_attempt"`
}

PendingHook 是已完成框架撤销、待重试业务事件 Hook 的标准记录。

type RedisEvalClient

type RedisEvalClient interface {
	EvalCtx(context.Context, string, []string, ...interface{}) (interface{}, error)
}

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

RedisStore 使用 go-zero Redis 客户端和 Lua 作为共享模式的权威存储。

func NewConfiguredRedisStore

func NewConfiguredRedisStore(cfg config.AuthRevocationRedisConfig) (*RedisStore, error)

func NewRedisStore

func NewRedisStore(client RedisEvalClient, prefix string) *RedisStore

func (*RedisStore) AckHook

func (*RedisStore) AckHook(context.Context, string) error

func (*RedisStore) Apply

func (s *RedisStore) Apply(ctx context.Context, event types.CasdoorEvent, retention time.Duration) (ApplyResult, error)

func (*RedisStore) Close

func (*RedisStore) Close() error

func (*RedisStore) ConfirmActive

func (s *RedisStore) ConfirmActive(ctx context.Context, key IdentityKey, expectedGeneration uint64) (State, error)

func (*RedisStore) Current

func (s *RedisStore) Current(ctx context.Context, key IdentityKey) (State, error)

func (*RedisStore) MarkControlPublished

func (s *RedisStore) MarkControlPublished(ctx context.Context, event types.CasdoorEvent) error

func (*RedisStore) MarkPendingHookReady

func (*RedisStore) MarkPendingHookReady(context.Context, string) error

func (*RedisStore) PendingHooks

func (*RedisStore) PendingHooks(context.Context, int) ([]PendingHook, error)

func (*RedisStore) SavePendingHook

func (*RedisStore) SavePendingHook(context.Context, PendingHook) error

func (*RedisStore) SaveSnapshot

func (s *RedisStore) SaveSnapshot(context.Context, State) error

type State

type State struct {
	Key        IdentityKey `json:"key"`
	Generation uint64      `json:"generation"`
	Blocked    bool        `json:"blocked"`
	EventOrder int64       `json:"event_order"`
	UID        string      `json:"uid,omitempty"`
	UpdatedAt  time.Time   `json:"updated_at"`
}

State 是身份撤销权威中的单调状态。

type Store

type Store interface {
	Current(context.Context, IdentityKey) (State, error)
	Apply(context.Context, types.CasdoorEvent, time.Duration) (ApplyResult, error)
	ConfirmActive(context.Context, IdentityKey, uint64) (State, error)
	SaveSnapshot(context.Context, State) error
	MarkControlPublished(context.Context, types.CasdoorEvent) error
	SavePendingHook(context.Context, PendingHook) error
	MarkPendingHookReady(context.Context, string) error
	PendingHooks(context.Context, int) ([]PendingHook, error)
	AckHook(context.Context, string) error
	Close() error
}

Store 是本地 Badger 与共享 Redis 共用的撤销权威契约。

Jump to

Keyboard shortcuts

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