auth

package
v0.0.0-...-3a12293 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: AGPL-3.0, Apache-2.0, CC-BY-SA-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrObsoleteToken = errors.New("obsolete token format")
	ErrTokenFormat   = errors.New("badly formatted token")
	ErrSalted        = errors.New("token already salted")
)
View Source
var DecodeTokenCookie func(string) ([]byte, error) = base64.URLEncoding.DecodeString

DecodeTokenCookie accepts a cookie value and returns the encoded token.

View Source
var EncodeTokenCookie func([]byte) string = base64.URLEncoding.EncodeToString

EncodeTokenCookie accepts a token and returns a byte slice suitable for use as a cookie value, such that it will be decoded correctly by LoadTokensFromHTTPRequest.

Functions

func LoadToken

func LoadToken(next http.Handler) http.Handler

LoadToken wraps the next handler, adding credentials to the request context so subsequent handlers can access them efficiently via CredentialsFromRequest.

func NewContext

func NewContext(ctx context.Context, c *Credentials) context.Context

func RequireLiteralToken

func RequireLiteralToken(token string, next http.Handler) http.Handler

RequireLiteralToken wraps the next handler, rejecting any request that doesn't supply the given token. If the given token is empty, RequireLiteralToken returns next (i.e., no auth checks are performed).

func SaltToken

func SaltToken(token, remote string) (string, error)

Types

type Credentials

type Credentials struct {
	Tokens []string
}

func CredentialsFromRequest

func CredentialsFromRequest(r *http.Request) *Credentials

func FromContext

func FromContext(ctx context.Context) (*Credentials, bool)

func NewCredentials

func NewCredentials(tokens ...string) *Credentials

func (*Credentials) LoadTokensFromHTTPRequest

func (a *Credentials) LoadTokensFromHTTPRequest(r *http.Request)

LoadTokensFromHTTPRequest loads all tokens it can find in the headers and query string of an http query.

func (*Credentials) LoadTokensFromHTTPRequestBody

func (a *Credentials) LoadTokensFromHTTPRequestBody(r *http.Request) error

LoadTokensFromHTTPRequestBody loads credentials from the request body.

This is separate from LoadTokensFromHTTPRequest() because it's not always desirable to read the request body. This has to be requested explicitly by the application.

Jump to

Keyboard shortcuts

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