bearer

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BearerAuthError added in v0.0.5

type BearerAuthError struct {
	Message string
	Err     error
}

BearerAuthError represents a bearer authentication error

func (*BearerAuthError) Error added in v0.0.5

func (e *BearerAuthError) Error() string

func (*BearerAuthError) Unwrap added in v0.0.5

func (e *BearerAuthError) Unwrap() error

type BearerStrategy added in v0.0.5

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

BearerStrategy implements authentication via Bearer tokens in Authorization header This strategy extracts session tokens from "Authorization: Bearer <token>" headers and validates them as session tokens (not JWT tokens)

func NewBearerStrategy added in v0.0.5

func NewBearerStrategy(
	sessionSvc session.ServiceInterface,
	userSvc user.ServiceInterface,
	config Config,
	logger forge.Logger,
) *BearerStrategy

NewBearerStrategy creates a new bearer token authentication strategy

func (*BearerStrategy) Authenticate added in v0.0.5

func (s *BearerStrategy) Authenticate(ctx context.Context, credentials interface{}) (*contexts.AuthContext, error)

Authenticate validates the bearer token and builds auth context

func (*BearerStrategy) Extract added in v0.0.5

func (s *BearerStrategy) Extract(c forge.Context) (interface{}, bool)

Extract attempts to extract a bearer token from the Authorization header

func (*BearerStrategy) ID added in v0.0.5

func (s *BearerStrategy) ID() string

ID returns the strategy identifier

func (*BearerStrategy) Priority added in v0.0.5

func (s *BearerStrategy) Priority() int

Priority returns the strategy priority (20 = medium-high priority for bearer tokens) This runs after API keys (10) but before cookies (30)

type Config

type Config struct {
	// TokenPrefix is the expected prefix for bearer tokens
	TokenPrefix string `json:"tokenPrefix"`
	// ValidateIssuer checks the token issuer
	ValidateIssuer bool `json:"validateIssuer"`
	// RequireScopes enforces scope validation
	RequireScopes []string `json:"requireScopes"`
	// CaseSensitive makes token comparison case-sensitive
	CaseSensitive bool `json:"caseSensitive"`
}

Config holds the bearer plugin configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default bearer plugin configuration

type Plugin

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

Plugin implements bearer token authentication middleware

func NewPlugin

func NewPlugin(opts ...PluginOption) *Plugin

NewPlugin creates a new bearer token plugin with optional configuration

func (*Plugin) AuthenticateHandler

func (p *Plugin) AuthenticateHandler(next func(forge.Context) error) func(forge.Context) error

AuthenticateHandler returns a handler function that can be used as middleware

func (*Plugin) ID

func (p *Plugin) ID() string

ID returns the plugin identifier

func (*Plugin) Init

func (p *Plugin) Init(authInst core.Authsome) error

Init initializes the bearer plugin

func (*Plugin) Migrate added in v0.0.5

func (p *Plugin) Migrate() error

Migrate runs plugin migrations (no-op for bearer - no database tables)

func (*Plugin) RegisterHooks added in v0.0.5

func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error

RegisterHooks registers plugin hooks (no-op for bearer)

func (*Plugin) RegisterRoutes added in v0.0.5

func (p *Plugin) RegisterRoutes(_ forge.Router) error

RegisterRoutes registers plugin routes (no-op for bearer - it's middleware-only)

func (*Plugin) RegisterServiceDecorators

func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error

RegisterServiceDecorators registers service decorators (no-op for bearer)

func (*Plugin) RequireAuthHandler

func (p *Plugin) RequireAuthHandler(next func(forge.Context) error) func(forge.Context) error

RequireAuthHandler returns a handler that requires authentication

type PluginOption

type PluginOption func(*Plugin)

PluginOption is a functional option for configuring the bearer plugin

func WithDefaultConfig

func WithDefaultConfig(cfg Config) PluginOption

WithDefaultConfig sets the default configuration for the plugin

func WithRequireScopes

func WithRequireScopes(scopes []string) PluginOption

WithRequireScopes sets the required scopes

func WithTokenPrefix

func WithTokenPrefix(prefix string) PluginOption

WithTokenPrefix sets the token prefix

func WithValidateIssuer

func WithValidateIssuer(validate bool) PluginOption

WithValidateIssuer sets whether to validate the issuer

Jump to

Keyboard shortcuts

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