ujwt

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2019 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSecretKey reports that secret key is empty.
	ErrInvalidSecretKey = errors.New("secret key is empty")

	// ErrInvalidSiginingMethod reports that signing method is invalid.
	ErrInvalidSiginingMethod = errors.New("invalid signing method")

	// ErrInvalidUser reports that user is empty.
	ErrInvalidUser = errors.New("user is empty")
)

Functions

func Issue

func Issue(secretKey, user, domain string, roles []string) (string, error)

Issue creates a new JWT.

func Parse

func Parse(secretKey, token string, c *Claims) error

Parse validates and decrypts a JWT and fills c with its payload.

Types

type Claims

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

Claims is the payload for JWT.

func (*Claims) HasRole

func (c *Claims) HasRole(role string) bool

HasRole returns true if claim has a specific role, and false otherwise.

func (*Claims) User

func (c *Claims) User() string

User returns the authenticated user.

Jump to

Keyboard shortcuts

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