auth

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeNone   = "none"
	ModeBearer = "bearer"
	ModeOpen   = "open"
)
View Source
const AgentTokenPrefix = "magt_v1_"
View Source
const CookieName = "moltnet_auth"

Variables

This section is empty.

Functions

func AgentTokenCredentialKey added in v0.1.1

func AgentTokenCredentialKey(token string) string

func GenerateAgentToken added in v0.1.1

func GenerateAgentToken() (string, error)

func LooksLikeAgentToken added in v0.1.1

func LooksLikeAgentToken(token string) bool

func ModeFromContext added in v0.1.1

func ModeFromContext(ctx context.Context) string

func RequestToken added in v0.1.1

func RequestToken(request *http.Request) (string, bool, error)

func StaticCredentialKey added in v0.1.1

func StaticCredentialKey(tokenID string) string

func WithClaims

func WithClaims(ctx context.Context, claims Claims) context.Context

func WithMode added in v0.1.1

func WithMode(ctx context.Context, mode string) context.Context

Types

type Claims

type Claims struct {
	TokenID       string
	CredentialKey string
	// contains filtered or unexported fields
}

func ClaimsFromContext

func ClaimsFromContext(ctx context.Context) (Claims, bool)

func NewAgentTokenClaims added in v0.1.1

func NewAgentTokenClaims(agentID string, credentialKey string) Claims

func NewCredentialClaims added in v0.1.1

func NewCredentialClaims(credentialKey string) Claims

func NewStaticClaims added in v0.1.1

func NewStaticClaims(config TokenConfig) Claims

func (Claims) AgentToken added in v0.1.1

func (c Claims) AgentToken() bool

func (Claims) Allows

func (c Claims) Allows(scope Scope) bool

func (Claims) AllowsAgent

func (c Claims) AllowsAgent(agentID string) bool

func (Claims) AllowsAny added in v0.1.1

func (c Claims) AllowsAny(scopes []Scope) bool

func (Claims) HasAgentRestriction added in v0.1.1

func (c Claims) HasAgentRestriction() bool

func (Claims) StaticToken added in v0.1.1

func (c Claims) StaticToken() bool

type Config

type Config struct {
	Mode                string
	ListenAddr          string
	AllowedOrigins      []string
	TrustForwardedProto bool
	Tokens              []TokenConfig
}

type Error

type Error struct {
	Status  int
	Message string
}

func (*Error) Error

func (e *Error) Error() string

type Policy

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

func NewPolicy

func NewPolicy(config Config) (*Policy, error)

func (*Policy) AuthenticateRequest

func (p *Policy) AuthenticateRequest(request *http.Request, scope Scope) (Claims, error)

func (*Policy) AuthenticateToken added in v0.1.1

func (p *Policy) AuthenticateToken(value string, scope Scope) (Claims, error)

func (*Policy) Bearer added in v0.1.1

func (p *Policy) Bearer() bool

func (*Policy) CheckOrigin

func (p *Policy) CheckOrigin(request *http.Request) bool

func (*Policy) Enabled

func (p *Policy) Enabled() bool

func (*Policy) IsSecureRequest

func (p *Policy) IsSecureRequest(request *http.Request) bool

func (*Policy) Mode added in v0.1.1

func (p *Policy) Mode() string

func (*Policy) None added in v0.1.1

func (p *Policy) None() bool

func (*Policy) Open added in v0.1.1

func (p *Policy) Open() bool

func (*Policy) StaticClaimsForToken added in v0.1.1

func (p *Policy) StaticClaimsForToken(value string) (Claims, bool)

type Scope

type Scope string
const (
	ScopeObserve Scope = "observe"
	ScopeWrite   Scope = "write"
	ScopeAdmin   Scope = "admin"
	ScopeAttach  Scope = "attach"
	ScopePair    Scope = "pair"
)

type TokenConfig

type TokenConfig struct {
	ID     string
	Value  string
	Scopes []Scope
	Agents []string
}

Jump to

Keyboard shortcuts

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