auth

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrVerifiedEmailRequired = errors.New("verified email required")

Functions

func NaviktMiddleware(
	v *NaviktVerifier,
	sm *scs.SessionManager,
	q db.Querier,
	adminGroups []string,
	allowedDomains []string,
	sessionHMACKey string,
) func(http.Handler) http.Handler

NaviktMiddleware verifies the Bearer token injected by the Wonderwall proxy, populates the SessionUser context, and only touches the DB on cache misses. Requests without a valid token (or with a token that fails verification) continue unauthenticated — the RequireLoginExcept middleware enforces the gate.

If the token's groups[] contains any entry in adminGroups, the role is promoted to "admin" for the duration of this request. Otherwise the stored DB role is used.

func UserMiddleware

func UserMiddleware(sm *scs.SessionManager, q db.Querier) func(http.Handler) http.Handler

UserMiddleware reads the authenticated user ID from the SCS session and injects a SessionUser into the request context. Requests with no session or an invalid user ID continue unauthenticated.

Types

type AuthRequestOptions

type AuthRequestOptions struct {
	CodeVerifier string
	Nonce        string
}

Provider abstracts a single OAuth2/OIDC login flow.

type ExchangeOptions

type ExchangeOptions struct {
	CodeVerifier string
	Nonce        string
}

type GitHubProvider

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

func NewGitHubProvider

func NewGitHubProvider(clientID, clientSecret, callbackURL string) *GitHubProvider

func (*GitHubProvider) AuthCodeURL

func (p *GitHubProvider) AuthCodeURL(state string, _ AuthRequestOptions) string

func (*GitHubProvider) Exchange

func (p *GitHubProvider) Exchange(ctx context.Context, code string, _ ExchangeOptions) (Identity, error)

func (*GitHubProvider) Name

func (p *GitHubProvider) Name() string

type Identity

type Identity struct {
	Provider   string // "github" | "oidc"
	ProviderID string // stable subject ID
	Email      string
	Name       string
}

Identity is the normalised result from any OAuth2/OIDC provider.

type NaviktClaims struct {
	NAVident          string   `json:"NAVident"`
	PreferredUsername string   `json:"preferred_username"`
	Name              string   `json:"name"`
	Groups            []string `json:"groups"`
}

NaviktClaims holds the token claims extracted from a NAIS/Entra ID bearer token.

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

NaviktVerifier verifies Entra ID bearer tokens injected by the Wonderwall proxy. It validates the signature against the JWKS endpoint and checks iss, aud, exp.

func NewNaviktVerifier added in v1.2.4

func NewNaviktVerifier(ctx context.Context, issuer, clientID, jwksURI string) *NaviktVerifier

NewNaviktVerifier constructs a NaviktVerifier that fetches signing keys from the given JWKS URI and validates against the provided issuer and client ID.

func (v *NaviktVerifier) Verify(ctx context.Context, rawToken string) (NaviktClaims, error)

Verify validates the raw bearer token and extracts NAIS-specific claims. It checks signature, issuer, audience, and expiry.

type OIDCProvider

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

func NewEntraIDProvider

func NewEntraIDProvider(ctx context.Context, tenantID, clientID, clientSecret, callbackURL string) (*OIDCProvider, error)

NewEntraIDProvider constructs an OIDCProvider pointed at the Microsoft Entra ID v2.0 endpoint for the given tenant.

func NewOIDCProvider

func NewOIDCProvider(ctx context.Context, name, issuerURL, clientID, clientSecret, callbackURL string) (*OIDCProvider, error)

NewOIDCProvider creates a generic OIDC provider. name is the slug used in callback URLs and stored as the provider discriminator (e.g. "oidc", "entra").

func (*OIDCProvider) AuthCodeURL

func (p *OIDCProvider) AuthCodeURL(state string, opts AuthRequestOptions) string

func (*OIDCProvider) Exchange

func (p *OIDCProvider) Exchange(ctx context.Context, code string, opts ExchangeOptions) (Identity, error)

func (*OIDCProvider) Name

func (p *OIDCProvider) Name() string

type Provider

type Provider interface {
	// Name returns the slug used in callback URLs (e.g. "github").
	Name() string
	// AuthCodeURL returns the redirect URL the browser should visit.
	AuthCodeURL(state string, opts AuthRequestOptions) string
	// Exchange completes the flow: exchanges the code and returns an Identity.
	Exchange(ctx context.Context, code string, opts ExchangeOptions) (Identity, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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