jwt

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2019 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyLength return when specified key not equal 512 bit, or 64 bytes
	ErrKeyLength = errors.New("Length of the specified key not equal 512 bits, or 64 bytes")

	// ErrCorruptedToken return when specified JWT in user request does't have one or more requered parts of JWT
	// JWT must contain header, payload and signature separated by dot
	ErrCorruptedToken = errors.New("Your JWT is corrupted and/or does't match the required")

	// ErrTokenExpired return when token has expired
	ErrTokenExpired = errors.New("Your token has expired")
)

Functions

func GenerateNewToken

func GenerateNewToken(header Header, payload *Payload, key string) (string, error)

GenerateNewToken generate and return new JWT

func ValidateToken

func ValidateToken(jwt, key string) (bool, error)

ValidateToken check validity of the JWT

Types

type AuthRoom

type AuthRoom struct {
	UUID   string `json:"uuid"`
	Passwd string `json:"passwd"`
}

AuthRoom is a list where user authorized

type Header struct {
	Aig string
}

Header information in JWT

type Payload

type Payload struct {
	UUID      string
	IsAdmin   bool `json:"is_admin"`
	Roles     []Role
	AuthRooms []AuthRoom `json:"auth_rooms"`
	Exp       int64
}

Payload information in JWT about user

func UnmarshalPayload

func UnmarshalPayload(token string) (*Payload, error)

UnmarshalPayload unmarshal payload from token and return it

func (Payload) CheckAuthStatus

func (p Payload) CheckAuthStatus(uuid string, hash []byte) error

CheckAuthStatus check auth status in room

func (Payload) GetLevel

func (p Payload) GetLevel(uuid string) (int, bool)

GetLevel return permissions level for a room

func (*Payload) SetAuthStatus

func (p *Payload) SetAuthStatus(uuid, passwd string)

SetAuthStatus set up new auth session for a room

func (*Payload) SetLevel

func (p *Payload) SetLevel(uuid string, level int)

SetLevel set up new permissions level for a room

type Role

type Role struct {
	UUID  string `json:"room_uuid"`
	Level int
}

Role describes information about where user is owner and what is him Permissions

Jump to

Keyboard shortcuts

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