accessgate

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultResumeTTL       = 12 * time.Hour
	DefaultLocalSessionTTL = 12 * time.Hour
	LocalSessionCookieName = "redeven_local_access"
)
View Source
const DefaultFailedAttemptRetention = 30 * time.Minute

Variables

View Source
var ErrInvalidPassword = errors.New("invalid password")

Functions

func IsRateLimited

func IsRateLimited(err error) bool

func RegisterTyped

func RegisterTyped[TReq any, TResp any](r *rpc.Router, typeID uint32, gate *Gate, meta *session.Meta, policy RPCAccessPolicy, h func(ctx context.Context, req *TReq) (*TResp, error))

func RequireRPC

func RequireRPC(gate *Gate, meta *session.Meta, policy RPCAccessPolicy) error

func RetryAfter

func RetryAfter(err error) time.Duration

Types

type AttemptPolicy

type AttemptPolicy struct {
	Steps     []AttemptPolicyStep
	Retention time.Duration
}

type AttemptPolicyStep

type AttemptPolicyStep struct {
	Failures int
	Cooldown time.Duration
}

type Gate

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

func New

func New(opts Options) *Gate

func (*Gate) CanResumeMeta

func (g *Gate) CanResumeMeta(resumeToken string, meta session.Meta) bool

func (*Gate) Enabled

func (g *Gate) Enabled() bool

func (*Gate) IsChannelUnlocked

func (g *Gate) IsChannelUnlocked(channelID string) bool

func (*Gate) IsLocalSessionValid

func (g *Gate) IsLocalSessionValid(token string) bool

func (*Gate) MintLocalSession

func (g *Gate) MintLocalSession(password string) (*LocalSessionResult, error)

func (*Gate) MintLocalSessionFromResumeToken

func (g *Gate) MintLocalSessionFromResumeToken(resumeToken string, meta session.Meta) (*LocalSessionResult, error)

func (*Gate) MintLocalSessionWithSubject

func (g *Gate) MintLocalSessionWithSubject(password string, subject string) (*LocalSessionResult, error)

func (*Gate) MintTrustedLocalSession added in v0.7.1

func (g *Gate) MintTrustedLocalSession(meta session.Meta) (*LocalSessionResult, error)

func (*Gate) RegisterChannel

func (g *Gate) RegisterChannel(meta session.Meta)

func (*Gate) RegisterChannelWithOptions

func (g *Gate) RegisterChannelWithOptions(meta session.Meta, opts RegisterChannelOptions)

func (*Gate) ResumeChannel

func (g *Gate) ResumeChannel(channelID string, resumeToken string) error

func (*Gate) RevokeLocalSession

func (g *Gate) RevokeLocalSession(token string)

func (*Gate) RevokeResumeToken

func (g *Gate) RevokeResumeToken(resumeToken string)

func (*Gate) Status

func (g *Gate) Status(channelID string) Status

func (*Gate) UnlockChannel

func (g *Gate) UnlockChannel(channelID string, password string) (*UnlockResult, error)

func (*Gate) UnlockChannelWithSubject

func (g *Gate) UnlockChannelWithSubject(channelID string, password string, subject string) (*UnlockResult, error)

func (*Gate) UnregisterChannel

func (g *Gate) UnregisterChannel(channelID string)

func (*Gate) VerifyPassword

func (g *Gate) VerifyPassword(password string) bool

type LocalSessionResult

type LocalSessionResult struct {
	Unlocked             bool   `json:"unlocked"`
	SessionToken         string `json:"-"`
	SessionExpiresAtUnix int64  `json:"session_expires_at_unix_ms,omitempty"`
	ResumeToken          string `json:"resume_token,omitempty"`
	ResumeExpiresAtUnix  int64  `json:"resume_expires_at_unix_ms,omitempty"`
}

type Options

type Options struct {
	Logger          *slog.Logger
	Password        string
	ResumeTTL       time.Duration
	LocalSessionTTL time.Duration
	AttemptPolicy   AttemptPolicy
}

type RPCAccessPolicy

type RPCAccessPolicy int
const (
	RPCAccessProtected RPCAccessPolicy = iota
	RPCAccessPublic
)

type RateLimitError

type RateLimitError struct {
	RetryAfter time.Duration
}

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type RegisterChannelOptions

type RegisterChannelOptions struct {
	Unlocked bool
}

type Status

type Status struct {
	PasswordRequired bool   `json:"password_required"`
	Unlocked         bool   `json:"unlocked"`
	FloeApp          string `json:"floe_app,omitempty"`
	CodeSpaceID      string `json:"code_space_id,omitempty"`
	SessionKind      string `json:"session_kind,omitempty"`
}

type UnlockResult

type UnlockResult struct {
	Unlocked            bool   `json:"unlocked"`
	ResumeToken         string `json:"resume_token,omitempty"`
	ResumeExpiresAtUnix int64  `json:"resume_expires_at_unix_ms,omitempty"`
}

Jump to

Keyboard shortcuts

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