Documentation
¶
Overview ¶
Package bearer provides a middleware that authenticates requests with an "Authorization: Bearer <token>" header obtained from a TokenSource.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(src TokenSource) middlewares.Middleware
New returns a middleware that sets "Authorization: Bearer <token>" on every request. Tokens are cached and refreshed shortly before expiry (oauth2.ReuseTokenSource semantics, safe for concurrent use).
The middleware fails fast: if the token source errors or returns an empty token the request is not sent, and if the request already carries an Authorization header it is rejected rather than silently overwritten.
Types ¶
type TokenSource ¶
TokenSource is compatible with golang.org/x/oauth2.TokenSource, so credentials from golang.org/x/oauth2/google (or any oauth2 source) can be passed in directly.