bearer

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 5 Imported by: 3

Documentation

Overview

Package bearer provides authentication strategy, to authenticate HTTP requests based on the bearer token.

Deprecated: Use token Strategy instead.

Index

Constants

View Source
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

View Source
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

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 NewStatic

func NewStatic(tokens map[string]auth.Info) auth.Strategy

NewStatic returns static auth.Strategy, populated from a map.

func NewStaticFromFile

func NewStaticFromFile(path string) (auth.Strategy, error)

NewStaticFromFile returns static auth.Strategy, populated from a CSV file.

func NoOpAuthenticate

func NoOpAuthenticate(ctx context.Context, r *http.Request, token string) (auth.Info, error)

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.

func Token

func Token(r *http.Request) (string, error)

Token return bearer token from Authorization header, or ErrInvalidToken, The returned token will not contain "Bearer" keyword

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.

type Static

type Static = token.Static

Static implements auth.Strategy and define a synchronized map honor all predefined bearer tokens.

Jump to

Keyboard shortcuts

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