Codebase list golang-github-go-kit-kit / 8c6ad4e auth / basic / README.md
8c6ad4e

Tree @8c6ad4e (Download .tar.gz)

README.md @8c6ad4eraw · history · blame

`package auth/basic` provides a Basic Authentication middleware [Mozilla article](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).

## Usage

```go
import httptransport "github.com/go-kit/kit/transport/http"

httptransport.NewServer(
		endpoint.Chain(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 a HTTP request we need to pass it through the context with something like ```httptransport.ServerBefore(httptransport.PopulateRequestContext)```.