basic

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 10 Imported by: 0

README

This package provides a Basic Authentication middleware.

It'll try to compare credentials from Authentication request header to a username/password pair in middleware constructor.

More details about this type of authentication can be found in Mozilla article.

Usage

import httptransport "github.com/crazyscoop/kit/transport/http"

httptransport.NewServer(
		AuthMiddleware(cfg.auth.user, cfg.auth.password, "Example Realm")(makeUppercaseEndpoint()),
		decodeMappingsRequest,
		httptransport.EncodeJSONResponse,
		httptransport.ServerBefore(httptransport.PopulateRequestContext),
	)

For AuthMiddleware to be able to pick up the Authentication header from an HTTP request we need to pass it through the context with something like httptransport.ServerBefore(httptransport.PopulateRequestContext).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(requiredUser, requiredPassword, realm string) endpoint.Middleware

AuthMiddleware returns a Basic Authentication middleware for a particular user and password.

Types

type AuthError

type AuthError struct {
	Realm string
}

AuthError represents an authorization error.

func (AuthError) Error

func (AuthError) Error() string

Error is an implementation of the Error interface.

func (AuthError) Headers

func (e AuthError) Headers() http.Header

Headers is an implementation of the Headerer interface in go-kit/http.

func (AuthError) StatusCode

func (AuthError) StatusCode() int

StatusCode is an implementation of the StatusCoder interface in go-kit/http.

Jump to

Keyboard shortcuts

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