cjwt

package
v0.0.0-...-a47b674 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJWT

func NewJWT(claims *CustomClaims, signingMethod jwt.SigningMethod) *jwt.Token

NewJWT returns a token given claims and a specified signing method

func SignJWT

func SignJWT(tk *jwt.Token, key *rsa.PrivateKey) (string, error)

SignJWT signs a JSON Web Token with a given private key

Types

type CustomClaims

type CustomClaims struct {
	/* _______StandardClaims:______________
	Audience  string `json:"aud,omitempty"`
	ExpiresAt int64  `json:"exp,omitempty"`
	Id        string `json:"jti,omitempty"`
	IssuedAt  int64  `json:"iat,omitempty"`
	Issuer    string `json:"iss,omitempty"`
	NotBefore int64  `json:"nbf,omitempty"`
	Subject   string `json:"sub,omitempty"`
	______________________________________*/
	jwt.StandardClaims

	Groups []string `json:"grps,omitempty"`
}

CustomClaims represents claims we wish to make and verify with JWTs

func NewCustomClaims

func NewCustomClaims(sub, aud, iss string, grps []string, lifetime time.Duration) *CustomClaims

NewCustomClaims returns a new CustomClaims object

func StdClaimsToCustomClaims

func StdClaimsToCustomClaims(stdClaims *jwt.MapClaims) (*CustomClaims, error)

StdClaimsToCustomClaims populates a CustomClaims struct with a given map of std claims

func ValidateJWT

func ValidateJWT(tkString, iss, aud, url string, grps []string) (*CustomClaims, error)

ValidateJWT returns the claims within a token as a CustomClaims obect and validates its fields

func (*CustomClaims) HasGroup

func (c *CustomClaims) HasGroup(groupID string) bool

HasGroup returns true if a CustomClaims object contains a given group as part of its grp claims

Jump to

Keyboard shortcuts

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