jwt

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

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	SystemRole    = "SYSTEM"
	AdminRole     = "ADMIN"
	AnonymousRole = "ANONYMOUS"
)

Common roles

Variables

View Source
var (
	ErrInvalidTokenContent = errors.New("invalid token content")
	ErrInvalidToken        = errors.New("token is invalid")
	ErrExpiredToken        = errors.New("token has expired")
)

Common errors.

Functions

This section is empty.

Types

type Credentials

type Credentials struct {
	Issuer string `json:"issuer"`
	Secret string `json:"secret"`
}

Credentials credentials to issue and verify JWT tokens.

type Issuer

type Issuer interface {
	Issue(user User, lifetime time.Duration) (string, error)
}

Issuer interface for issuing auth tokens

func NewIssuer

func NewIssuer(creds Credentials) Issuer

NewIssuer creates a new Issuer using the default implementation.

type User

type User struct {
	ID    string
	Roles []string
}

User user authenicatated in JWT.

func (User) HasRole

func (u User) HasRole(candidate string) bool

HasRole checks if a users has a given role.

func (User) IsAdmin

func (u User) IsAdmin() bool

IsAdmin checks if a user has the ADMIN role.

func (User) IsAnonymous

func (u User) IsAnonymous() bool

IsAnonymous checks if a user has the ANONYMOUS role.

func (User) IsSystem

func (u User) IsSystem() bool

IsSystem checks if a user has the SYSTEM role.

func (User) String

func (u User) String() string

type Verifier

type Verifier interface {
	Verify(token string) (User, error)
}

Verifier interface for verifying tokens.

func NewVerifier

func NewVerifier(creds Credentials, leeway time.Duration) Verifier

NewVerifier creates a new Verifier using the default implementation.

Jump to

Keyboard shortcuts

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