auth

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendQuery

func AppendQuery(raw string, values url.Values) string

func ConfiguredLoginValue

func ConfiguredLoginValue() string

func ConstantTimeEqual

func ConstantTimeEqual(a, b string) bool

func EquivalentResourceURI

func EquivalentResourceURI(left, right string) bool

func NewOAuthManager added in v0.6.0

func NewOAuthManager(
	store *OAuthStore,
	signingKey string,
	accessTTLSeconds int64,
	refreshTTL time.Duration,
) *manage.Manager

NewOAuthManager 使用 go-oauth2 自带的 Manager 承担授权码签发、PKCE 校验、 Access Token 签发、Refresh Token 轮换和 TokenStore 生命周期。AgentDock 只保留 动态客户端注册、MCP resource 约束以及持久化安全策略。

func ParseBearerToken

func ParseBearerToken(header string) (string, bool)

func RandomToken

func RandomToken(n int) (string, error)

func ValidPKCEChallenge

func ValidPKCEChallenge(challenge string) bool

func VerifyPKCE

func VerifyPKCE(verifier, challenge string) bool

func WithOAuthRequest added in v0.6.0

func WithOAuthRequest(ctx context.Context, issuer, resource, clientID string) context.Context

Types

type Bearer

type Bearer struct {
	Token string
}

func (Bearer) Authorized

func (b Bearer) Authorized(r *http.Request) bool

func (Bearer) Enabled

func (b Bearer) Enabled() bool

type OAuthClientRegistration

type OAuthClientRegistration struct {
	ClientName   string   `json:"client_name,omitempty"`
	RedirectURIs []string `json:"redirect_uris"`
	GrantTypes   []string `json:"grant_types"`
	IssuedAt     int64    `json:"issued_at"`
	LastUsedAt   int64    `json:"last_used_at,omitempty"`
}

type OAuthCode

type OAuthCode struct {
	ClientID    string
	RedirectURI string
	Challenge   string
	Resource    string
	GrantID     string
	Redeemed    bool
	ExpiresAt   time.Time
}

type OAuthGrant

type OAuthGrant struct {
	ClientID           string `json:"client_id"`
	Resource           string `json:"resource"`
	AccessTokenHash    string `json:"access_token_hash,omitempty"`
	AccessIssuedAt     int64  `json:"access_issued_at,omitempty"`
	AccessExpiresAt    int64  `json:"access_expires_at,omitempty"`
	AccessNeverExpires bool   `json:"access_never_expires,omitempty"`
	RefreshIssuedAt    int64  `json:"refresh_issued_at,omitempty"`
	CurrentGeneration  uint64 `json:"current_generation"`
	ExpiresAt          int64  `json:"expires_at"`
	Revoked            bool   `json:"revoked,omitempty"`
}

type OAuthStore

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

func NewOAuthStore

func NewOAuthStore() *OAuthStore

func NewPersistentOAuthStore

func NewPersistentOAuthStore(path, signingKey string) (*OAuthStore, error)

func (*OAuthStore) ClientAllowsGrant

func (s *OAuthStore) ClientAllowsGrant(clientID, grantType string) bool

func (*OAuthStore) ClientRegistration

func (s *OAuthStore) ClientRegistration(clientID string) (OAuthClientRegistration, bool)

func (*OAuthStore) Create

func (s *OAuthStore) Create(_ context.Context, info gooauth2.TokenInfo) error

Create 实现 go-oauth2 TokenStore。授权码保留在短期内存中;Access Token 只持久化 SHA-256,Refresh Token 只持久化代际,状态文件不保存原始令牌。

func (*OAuthStore) GetByAccess added in v0.6.0

func (s *OAuthStore) GetByAccess(ctx context.Context, raw string) (gooauth2.TokenInfo, error)

func (*OAuthStore) GetByCode added in v0.6.0

func (s *OAuthStore) GetByCode(ctx context.Context, raw string) (gooauth2.TokenInfo, error)

func (*OAuthStore) GetByRefresh added in v0.6.0

func (s *OAuthStore) GetByRefresh(ctx context.Context, raw string) (gooauth2.TokenInfo, error)

func (*OAuthStore) PruneExpiredClients

func (s *OAuthStore) PruneExpiredClients(now time.Time) (int, error)

func (*OAuthStore) RegisterClient

func (s *OAuthStore) RegisterClient(clientName string, redirectURIs, grantTypes []string) (string, error)

func (*OAuthStore) RemoveByAccess added in v0.6.0

func (s *OAuthStore) RemoveByAccess(_ context.Context, raw string) error

func (*OAuthStore) RemoveByCode added in v0.6.0

func (s *OAuthStore) RemoveByCode(_ context.Context, raw string) error

func (*OAuthStore) RemoveByRefresh added in v0.6.0

func (s *OAuthStore) RemoveByRefresh(_ context.Context, raw string) error

func (*OAuthStore) RevokeGrant

func (s *OAuthStore) RevokeGrant(grantID string, ttl time.Duration) error

func (*OAuthStore) ValidateClientID

func (s *OAuthStore) ValidateClientID(clientID string) bool

func (*OAuthStore) ValidateClientRedirect

func (s *OAuthStore) ValidateClientRedirect(clientID, redirectURI string) bool

Jump to

Keyboard shortcuts

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