Documentation ¶
Overview ¶
Package bearer provides authentication strategy, to authenticate HTTP requests based on the bearer token.
Deprecated: Use token Strategy instead.
Index ¶
- Constants
- Variables
- func New(auth AuthenticateFunc, c store.Cache) auth.Strategy
- func NewStatic(tokens map[string]auth.Info) auth.Strategy
- func NewStaticFromFile(path string) (auth.Strategy, error)
- func NoOpAuthenticate(ctx context.Context, r *http.Request, token string) (auth.Info, error)
- func Token(r *http.Request) (string, error)
- type AuthenticateFunc
- type Static
Constants ¶
const ( // CachedStrategyKey export identifier for the cached bearer strategy, // commonly used when enable/add strategy to go-guardian authenticator. CachedStrategyKey = token.CachedStrategyKey // StatitcStrategyKey export identifier for the static bearer strategy, // commonly used when enable/add strategy to go-guardian authenticator. StatitcStrategyKey = token.StatitcStrategyKey )
Variables ¶
var ( // ErrInvalidToken indicate a hit of an invalid bearer token format. // And it's returned by Token function. ErrInvalidToken = token.ErrInvalidToken // ErrTokenNotFound is returned by authenticating functions for bearer strategies, // when token not found in their store. ErrTokenNotFound = token.ErrTokenNotFound )
Functions ¶
func New ¶ added in v1.0.0
func New(auth AuthenticateFunc, c store.Cache) auth.Strategy
New return new auth.Strategy. The returned strategy, caches the invocation result of authenticate function, See AuthenticateFunc. Use NoOpAuthenticate to refresh/mangae token directly using cache or Append function, See NoOpAuthenticate.
func NewStaticFromFile ¶
NewStaticFromFile returns static auth.Strategy, populated from a CSV file.
func NoOpAuthenticate ¶
NoOpAuthenticate implements Authenticate function, it return nil, auth.ErrNOOP, commonly used when token refreshed/mangaed directly using cache or Append function, and there is no need to parse token and authenticate request.
Types ¶
type AuthenticateFunc ¶ added in v1.0.0
type AuthenticateFunc = token.AuthenticateFunc
AuthenticateFunc declare custom function to authenticate request using token. The authenticate function invoked by Authenticate Strategy method when The token does not exist in the cahce and the invocation result will be cached, unless an error returned. Use NoOpAuthenticate instead to refresh/mangae token directly using cache or Append function.