jwtmdl

package
v2.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalJWTKey string

GlobalJWTKey - key to decode and encode token

Functions

func DecodeToken

func DecodeToken(req *http.Request) (jwt.MapClaims, error)

DecodeToken decode token

func DecodeTokenWithJWTKey

func DecodeTokenWithJWTKey(req *http.Request, jwtKey string) (jwt.MapClaims, error)

DecodeTokenWithJWTKey decode token

func GeneratePricipleObjUsingToken

func GeneratePricipleObjUsingToken(tokenReq string, jwtKey string) (jwt.MapClaims, error)

GeneratePricipleObjUsingToken GeneratePricipleObjUsingToken

func GenerateToken

func GenerateToken(loginID string, groups []string, clientIP string, metadata gjson.Result, expirationTime time.Duration) (string, error)

GenerateToken generates JWT token from Login object

func GenerateTokenWithJWTKey

func GenerateTokenWithJWTKey(loginID string, groups []string, clientIP string, metadata gjson.Result, expirationTime time.Duration, JWTKey string) (string, error)

GenerateTokenWithJWTKey generates JWT token from Login object

func GenerateTokenWithOptions

func GenerateTokenWithOptions(args ...Option) (string, error)

Types

type Option

type Option func(*Options)

func WithClientIP

func WithClientIP(ip string) Option

func WithExpiration

func WithExpiration(e time.Duration) Option

WithExpiration adds provided expiration to jwt token. Use `0` or ignore this option to generate a token witout expiry.

func WithGroups

func WithGroups(gs []string) Option

func WithKey

func WithKey(k string) Option

WithKey uses provided jwt key for token generation

func WithMetaData

func WithMetaData(data string) Option

WithMetaData embeds provided data in token. It is available againt `metadata` key. **It must be a valid json**

func WithSession

func WithSession(sid, sessionFor string) Option

WithSession enables session validation on jwt decode. Required fields must not be empty.

func WithUserID

func WithUserID(uid string) Option

type Options

type Options struct {
	Key       string
	UserID    string
	ClientIP  string
	Metadata  string
	Groups    []string
	ExpiresAt int64
	Session   sessionmdl.Session
}

Jump to

Keyboard shortcuts

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