tokenauth

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceTokenHeader = "gitlab-iam-auth-token"
)

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized")

Functions

This section is empty.

Types

type Validator

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

Validator performs constant-time token validation against a set of pre-computed SHA512 hashes. It is safe for concurrent use.

func NewValidator

func NewValidator(tokens ...string) *Validator

NewValidator creates a Validator that accepts the given tokens. Empty token strings are silently ignored (supports optional next_service_token).

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, providedToken string) error

Validate checks whether the provided token matches any of the configured tokens. Returns nil on success, ErrUnauthorized on failure. Uses SHA512 hashing and constant-time comparison to prevent timing attacks. All hashes are checked without short-circuiting.

Jump to

Keyboard shortcuts

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