authn

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: Apache-2.0 Imports: 12 Imported by: 13

Documentation

Index

Constants

View Source
const (
	SessionKey = sessionKeyType("session")
)

Variables

View Source
var ErrNotEncoded = errors.New("token is not encoded with suffix")

ErrNotEncoded acts similarly to EOF - it does indicate there is no suffix in the token, but that does not have to be treated as the error in some cases. If token is not base64-encoded, the token is returned as a key alongside with the error.

Functions

func AuthPack added in v0.17.0

func AuthPack(prefix AuthPrefix, id, key string) string

Types

type AuthNMiddleware added in v0.18.1

type AuthNMiddleware interface {
	Authentication
	WithOptions(options ...MiddlewareOption) AuthNMiddleware
	Middleware() func(http.Handler) http.Handler
}

AuthNMiddleware defines the interface for authenticated services with middleware.

func NewAuthNMiddleware added in v0.18.1

func NewAuthNMiddleware(authnSvc Authentication, options ...MiddlewareOption) AuthNMiddleware

NewAuthNMiddleware creates a new authenticated service with middleware support. The order of precedence for options is as follows, with later options overriding earlier ones: 1. Default options (lowest precedence). 2. Options from environment variables (e.g., SMQ_ALLOW_UNVERIFIED_USER). 3. Options passed as arguments to this function (highest precedence).

For example, consider the 'allowUnverifiedUser' option:

  • By default, it is 'false'.
  • If the SMQ_ALLOW_UNVERIFIED_USER environment variable is set to "true", it becomes 'true'.
  • If NewAuthNMiddleware is called with WithAllowUnverifiedUser(false), it will be 'false', regardless of the environment variable, as function arguments have the highest precedence.

type AuthPrefix added in v0.17.0

type AuthPrefix int
const (
	Unknown AuthPrefix = iota
	BasicAuth
	DomainAuth
)

func AuthUnpack added in v0.17.0

func AuthUnpack(token string) (AuthPrefix, string, string, error)

func (AuthPrefix) String added in v0.17.0

func (a AuthPrefix) String() string

String returns the string representation (e.g., "Basic") of the AuthPrefix.

type Authentication

type Authentication interface {
	Authenticate(ctx context.Context, token string) (Session, error)
}

Authn is supermq authentication library.

type MiddlewareOption added in v0.18.1

type MiddlewareOption func(*middlewareOptions)

MiddlewareOption is a function that modifies middleware options.

func WithAllowUnverifiedUser added in v0.18.1

func WithAllowUnverifiedUser(allowed bool) MiddlewareOption

WithAllowUnverifiedUser sets whether unverified users are allowed.

func WithDefaultMiddlewareOptions added in v0.18.1

func WithDefaultMiddlewareOptions() MiddlewareOption

WithDefaultMiddlewareOptions resets options to default values.

func WithDomainCheck added in v0.18.1

func WithDomainCheck(enabled bool) MiddlewareOption

WithDomainCheck sets whether domain checking is enabled.

type Role added in v0.17.0

type Role uint32
const (
	UserRole Role = iota + 1
	AdminRole
)

type Session

type Session struct {
	Type         TokenType
	PatID        string
	UserID       string
	DomainID     string
	DomainUserID string
	SuperAdmin   bool
	Verified     bool
	Role         Role
}

type TokenType added in v0.17.0

type TokenType uint32
const (
	// AccessToken represents token generated by user.
	AccessToken TokenType = iota
	// PersonalAccessToken represents token generated by user for automation.
	PersonalAccessToken
)

func (TokenType) String added in v0.17.0

func (t TokenType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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