auth

package
v0.103.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth validates requests: an Azure AD token is tried first and, when the token isn't an Azure one (no kid, unknown kid), it falls back to a static RS256 key — for a secondary issuer, service-to-service tokens, or any other static key a deployment wants to trust alongside Azure AD.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAzureToken = errors.New("not an azure ad token")

ErrNotAzureToken means the token has no kid or a kid unknown to Azure AD, so the legacy validation must be tried (InvalidAuthorizationToken in eve_azure_ad_auth).

View Source
var ErrUnauthorized = errors.New("please provide proper credentials")

ErrUnauthorized is returned for missing or invalid credentials.

Functions

func TokenFromRequest

func TokenFromRequest(r *http.Request, cookieName string) string

TokenFromRequest extracts the token from the request, in this order:

Authorization: Basic base64(<token>:<anything>)  -> the username
Authorization: Token <token>
Authorization: Basic: <token>                     -> a bare "Basic:" prefix
Authorization: <token>
Cookie: <cookieName>=<token>

func WithClaims

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

WithClaims stores the claims in the context.

Types

type Authenticator

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

Authenticator validates requests.

func New

func New(cfg Config, azure *AzureVerifier) (*Authenticator, error)

New builds an Authenticator. A PublicKeyFile that fails to read or parse fails New, so a typo in the config never silently disables the fallback.

func (*Authenticator) Authenticate

func (a *Authenticator) Authenticate(r *http.Request) (Claims, error)

Authenticate validates the request token. With auth disabled it returns empty claims and no error.

func (*Authenticator) Azure

func (a *Authenticator) Azure() *AzureVerifier

Azure returns the Azure verifier, or nil when Azure is not configured.

func (*Authenticator) Enabled

func (a *Authenticator) Enabled() bool

Enabled reports whether authentication is enforced.

func (*Authenticator) VerifyLegacy

func (a *Authenticator) VerifyLegacy(token string) (Claims, error)

VerifyLegacy validates a token against the static RS256 key (Config.PublicKeyFile); with authentication disabled every token is valid.

type AzureVerifier

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

AzureVerifier validates Azure AD v2.0 tokens, like eve_azure_ad_auth.verifier.AzureVerifier, caching the signing keys.

func NewAzureVerifier

func NewAzureVerifier(tenant, issuer string, audiences []string) *AzureVerifier

NewAzureVerifier builds a verifier. An empty tenant means "common".

func (*AzureVerifier) Verify

func (v *AzureVerifier) Verify(ctx context.Context, token string) (Claims, error)

Verify validates signature, issuer and audience.

type Claims

type Claims map[string]any

Claims is the decoded token payload.

func FromContext

func FromContext(ctx context.Context) Claims

FromContext returns the claims of an authenticated request.

func (Claims) Username

func (c Claims) Username() string

Username returns the preferred_username or user claim, in that order.

type Config

type Config struct {
	Enabled bool
	// CookieName is read when no Authorization header carries a token
	// (default "token").
	CookieName string
	// PublicKeyFile is the static RS256 key for the legacy fallback (PEM or
	// "ssh-rsa ..."). Without it, that fallback is disabled: a non-Azure
	// token is simply rejected.
	PublicKeyFile string
	Tenant        string
	Issuer        string
	Audiences     []string
}

Config holds the authentication settings.

Jump to

Keyboard shortcuts

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