auth

package
v0.0.0-...-55af573 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleAdmin  = "ADMIN"
	RoleAuthor = "AUTHOR"
)

Variables

View Source
var ErrInvalidToken = errors.New("Invalid token")

Functions

func ContextWithUser

func ContextWithUser(ctx context.Context, claims Claims) context.Context

func CreateToken

func CreateToken(claims Claims) (string, error)

func HasRole

func HasRole(roles []string, wanted string) bool

func RolesFromContext

func RolesFromContext(ctx context.Context) ([]string, bool)

func UserFromContext

func UserFromContext(ctx context.Context) (string, bool)

Types

type Claims

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

func NewClaims

func NewClaims(userid string, roles []string) Claims

func ParseWithClaims

func ParseWithClaims(tokenStr string) (Claims, error)

Jump to

Keyboard shortcuts

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