webtoken

package
v0.0.0-...-4790e63 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotValidYet is when a token is used prior to the issue date.
	ErrNotValidYet = errors.New("token is not valid yet")
	// ErrExpired is when a token is used after the expiration date.
	ErrExpired = errors.New("token is expired")
	// ErrMalformed is when a token is malformed.
	ErrMalformed = errors.New("token is malformed")
	// ErrSignatureInvalid is when a signature is invalid.
	ErrSignatureInvalid = errors.New("signature is invalid")
	// ErrAudienceInvalid is when the audience is invalid.
	ErrAudienceInvalid = errors.New("audience is invalid")
	// ErrExpirationInvalid is when the expiration is invalid.
	ErrExpirationInvalid = errors.New("expiration is invalid")
	// ErrIssuedAtInvalid is when the issued date is invalid.
	ErrIssuedAtInvalid = errors.New("issue date is invalid")
	// ErrNotBeforeInvalid is when the before date is invalid.
	ErrNotBeforeInvalid = errors.New("before date is invalid")
	// ErrSecretTooShort is when the secret is not long enough.
	ErrSecretTooShort = errors.New("secret must be 256 bit (32 bytes)")
)

Functions

This section is empty.

Types

type Clock

type Clock struct{}

Clock is a standard system clock.

func (*Clock) Now

func (c *Clock) Now() time.Time

Now returns the current time.

type Configuration

type Configuration struct {
	// contains filtered or unexported fields
}

Configuration contains the JWT dependencies.

func New

func New(secret []byte, sessionTimeout time.Duration) *Configuration

New creates a new JWT configuration.

func (*Configuration) Generate

func (c *Configuration) Generate(userID string) (string, error)

Generate will generate a JWT.

func (*Configuration) SetClock

func (c *Configuration) SetClock(clock IClock)

SetClock will set the clock.

func (*Configuration) Verify

func (c *Configuration) Verify(s string) (string, error)

Verify will ensure a JWT is valid and returns the audience if successful.

type IClock

type IClock interface {
	Now() time.Time
}

IClock represents a system clock.

Jump to

Keyboard shortcuts

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