auth

package
v0.0.0-...-8fab053 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleAdmin    = "ADMIN"
	RoleSeller   = "SELLER"
	RoleCustomer = "CUSTOMER"
)

These are the expected values for Claims.Roles.

View Source
const Key ctxKey = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

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

func New

func New(algorithm string, lookup PublicKeyLookup, keys Keys) (*Auth, error)

func (*Auth) AddKey

func (a *Auth) AddKey(privateKey *rsa.PrivateKey, kid string)

func (*Auth) GenerateToken

func (a *Auth) GenerateToken(kid string, claims Claims) (string, error)

func (*Auth) RemoveKey

func (a *Auth) RemoveKey(kid string)

func (*Auth) ValidateToken

func (a *Auth) ValidateToken(tokenStr string) (Claims, error)

type Claims

type Claims struct {
	jwt.StandardClaims
	Roles []string `json:"roles"`
}

func (Claims) Authorized

func (c Claims) Authorized(roles ...string) bool

type Keys

type Keys map[string]*rsa.PrivateKey

type PublicKeyLookup

type PublicKeyLookup func(kid string) (*rsa.PublicKey, error)

Jump to

Keyboard shortcuts

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