jwt

package
v0.0.0-...-0cfb223 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScopeAllRead represents the global read permission scope
	ScopeAllRead = "read:all"

	// ScopeAllWrite represents the global write permission scope
	ScopeAllWrite = "write:all"

	// ScopeItemRead represents the item read permission scope
	ScopeItemRead = "read:item"

	// ScopeItemWrite represents the item write permission scope
	ScopeItemWrite = "write:item"

	// ScopeHideoutRead represents the hideout read permission scope
	ScopeHideoutRead = "read:hideout"

	// ScopeHideoutWrite represents the hideout write permission scope
	ScopeHideoutWrite = "write:hideout"

	// ScopeLocationRead represents the location read permission scope
	ScopeLocationRead = "read:location"

	// ScopeLocationWrite represents the location write permission scope
	ScopeLocationWrite = "write:location"

	// ScopeStatisticRead represents the statistic read permission scope
	ScopeStatisticRead = "read:statistic"

	// ScopeStatisticWrite represents the statistic write permission scope
	ScopeStatisticWrite = "write:statistic"

	// ScopeUserRead represents the user read permission scope
	ScopeUserRead = "read:user"

	// ScopeUserWrite represents the user write permission scope
	ScopeUserWrite = "write:user"

	// ScopeTokenWrite represents the token write permission scope
	ScopeTokenWrite = "write:token"
)

Variables

View Source
var (
	// ErrInvalidScope indicates that a scope value is not valid
	ErrInvalidScope = errors.New("no or invalid scopes")

	// ErrInvalidSubject indicates that the subject value is not valid
	ErrInvalidSubject = errors.New("invalid subject")

	// ErrInvalidAudience indicates that the audience value does not match
	ErrInvalidAudience = errors.New("audience mismatch")

	// ErrExpiredToken indicates that the token is expired
	ErrExpiredToken = errors.New("token is expired")

	// ErrNotBefore indicates that the token is not yet valid
	ErrNotBefore = errors.New("token is not yet valid")

	// ErrMalformed indicates that the token is malformed
	ErrMalformed = errors.New("token is malformed")

	// ErrInvalidToken indicates that the token is invalid
	ErrInvalidToken = errors.New("token is invalid")
)
View Source
var (
	// ErrNoAuthHeader indicates that the authorization is not set
	ErrNoAuthHeader = errors.New("authorization header not set")

	// ErrInvalidAuthHeader indicates that the authorization is invalid
	ErrInvalidAuthHeader = errors.New("invalid authorization header")
)

Functions

func AddAuthenticateHeader

func AddAuthenticateHeader(w http.ResponseWriter, err error, scopes ...string)

AddAuthenticateHeader adds the "WWW-Authenticate" header to the response

func AuhtorizationHandler

func AuhtorizationHandler(scope string, h httprouter.Handle) httprouter.Handle

AuhtorizationHandler returns a JWT authorization handler

func ExtractToken

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

ExtractToken extracts a token from a request header

func SignToken

func SignToken(c *Claims, d *time.Duration) (string, error)

SignToken signs a token

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	Scope []string `json:"scope"`
}

Claims represents the claims of a token

func VerifyToken

func VerifyToken(tokenStr string) (*Claims, error)

VerifyToken verifies a token

func (*Claims) Validate

func (c *Claims) Validate() error

ValidateCustom validates the custom claims of a token

Jump to

Keyboard shortcuts

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