Add Authenticator interface with AuthenticatorFunc adapter and built-in APIKeyAuthenticator for Bearer token validation. Hub.Handler() now gates connections when an Authenticator is configured on HubConfig, responding HTTP 401 for failed auth. Client.UserID and Client.Claims are populated on successful upgrade. OnAuthFailure callback enables logging/metrics. Nil authenticator preserves full backward compatibility — all existing tests pass unchanged. 18 new tests (unit + integration) cover valid/ invalid/missing/malformed headers, func adapter, multi-client auth, message delivery post-auth, and the OnAuthFailure callback. Co-Authored-By: Virgil <virgil@lethean.io>
19 lines
628 B
Go
19 lines
628 B
Go
// SPDX-Licence-Identifier: EUPL-1.2
|
|
|
|
package ws
|
|
|
|
import "errors"
|
|
|
|
// Authentication errors returned by the built-in APIKeyAuthenticator.
|
|
var (
|
|
// ErrMissingAuthHeader is returned when no Authorization header is present.
|
|
ErrMissingAuthHeader = errors.New("missing Authorization header")
|
|
|
|
// ErrMalformedAuthHeader is returned when the Authorization header is
|
|
// not in the expected "Bearer <token>" format.
|
|
ErrMalformedAuthHeader = errors.New("malformed Authorization header")
|
|
|
|
// ErrInvalidAPIKey is returned when the provided API key does not
|
|
// match any known key.
|
|
ErrInvalidAPIKey = errors.New("invalid API key")
|
|
)
|