Documentation
¶
Index ¶
Constants ¶
const (
DefaultXApiKeyHeaderName string = "X-Api-Key"
)
Variables ¶
var (
ErrNotAuthorized = errors.New("unauthorized")
)
Functions ¶
func AuthenticationMiddleware ¶ added in v0.0.45
func AuthenticationMiddleware(authFunc UserAuthenticationFunc) func(http.Handler) http.Handler
AuthenticationMiddleware is a middleware that authenticates the user through the given UserAuthenticationFunc and sets the user in the context.
func LoggingMiddleware ¶
LoggingMiddleware is a middleware that logs HTTP requests and responses. It extracts the request body and logs it. It also logs the request and response details.
func TelemetryMiddleware ¶ added in v0.0.38
TelemetryMiddleware is a middleware that wraps the provided http.ServeMux with OpenTelemetry instrumentation. It instruments the ServeMux with the otelhttp.NewHandler function and enables logging for all requests handled by the ServeMux.
Types ¶
type ApiKeyMap ¶ added in v0.0.45
type ApiKeyMap struct {
// contains filtered or unexported fields
}
ApiKeyMap stores hashed API keys grouped by a deterministic lookup token.
It uses a bucket index to reduce the amount of bcrypt comparisons performed on each request while still using bcrypt for the final key verification.
func NewApiKeyMapFromHashedMap ¶ added in v0.0.45
NewApiKeyMapFromHashedMap creates a new ApiKeyMap from a map of hashed API keys to users.
type User ¶ added in v0.0.45
User represents a user.
func AuthenticatedUserFromContext ¶ added in v0.0.45
AuthenticatedUserFromContext returns the authenticated user from the context.
type UserAuthenticationFunc ¶ added in v0.0.45
UserAuthenticationFunc is a function that authenticates a user based on the provided request.
func MultipleUserApiKeyAuthenticationFunc ¶ added in v0.0.45
func MultipleUserApiKeyAuthenticationFunc(authData ApiKeyMap, headerName string) UserAuthenticationFunc
MultipleUserApiKeyAuthenticationFunc authenticates the user based on the provided map of API keys to users.
func SingleUserApiKeyAuthenticationFunc ¶ added in v0.0.45
func SingleUserApiKeyAuthenticationFunc(apiKey, headerName string, user User) UserAuthenticationFunc
SingleUserApiKeyAuthenticationFunc authenticates the user based on the provided API key and user.