auth

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package auth resolves a credential to a caller identity. It is transport- neutral: it knows nothing about HTTP headers or status codes. The HTTP middleware extracts a credential from the request and calls Authenticate; when this graduates to JWT, only the Authenticator implementation changes, not this contract nor its callers.

Index

Constants

View Source
const XAuthHeaderKey = "X-Auth-Password"

XAuthHeaderKey is the request header carrying the shared password in the pre-JWT auth mode. The header is an HTTP detail owned here, not by the transport-neutral auth package.

Variables

View Source
var ErrUnauthenticated = errors.New("unauthenticated")

ErrUnauthenticated is returned when a credential does not resolve to a user.

Functions

func UserID

func UserID(ctx context.Context) (string, bool)

UserID returns the authenticated user ID stored in ctx, if present.

func WithUserID

func WithUserID(ctx context.Context, userID string) context.Context

WithUserID returns a copy of ctx carrying the authenticated user ID.

Types

type Authenticator

type Authenticator interface {
	Authenticate(credential string) (userID string, err error)
}

Authenticator resolves an opaque credential (a shared password today, a JWT later) to a user identifier.

type PasswordAuthenticator

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

PasswordAuthenticator is a static credential store mapping shared passwords to user IDs. It is the simple password mode that precedes real token auth.

func NewPasswordAuthenticator

func NewPasswordAuthenticator(users map[string]string) *PasswordAuthenticator

NewPasswordAuthenticator builds a PasswordAuthenticator from a password -> userID map.

func (*PasswordAuthenticator) Authenticate

func (a *PasswordAuthenticator) Authenticate(credential string) (string, error)

Authenticate returns the user ID mapped to credential, or ErrUnauthenticated.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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