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 ¶
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 ¶
var ErrUnauthenticated = errors.New("unauthenticated")
ErrUnauthenticated is returned when a credential does not resolve to a user.
Functions ¶
Types ¶
type Authenticator ¶
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.