Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
/ jwt-gowrapper Public archive

a wrapper of dgrijalva/jwt-go with storage interface

License

Notifications You must be signed in to change notification settings

yuchanns/jwt-gowrapper

Repository files navigation

jwt-gowrapper

circleci GoDoc

a wrapper of dgrijalva/jwt-go with storage interface

example

this example shows how this package work with a builtin redigo storage. Certainly users can implemented a custom storage by themselves.

  • generate a json web token:
// conn is an instance of redis.Conn from `github.com/gomodule/redigo/redis`
storage := NewStorageRedis(conn)
j := NewDefaultJwt(storage, secretKey, 2*time.Second)
token, err := j.Generate(jwt.MapClaims{
    "id":   111,
    "name": "yuchanns",
})
  • validate a jwt:

the validate method will expand the living time of the given token once it is valid.

err := j.Validate(token)
  • invalidate a jwt:
err := j.Invalidate(token)

custom storage

do implement the Storage interface below:

type Storage interface {
	// Check a key if it is exist and return its remaining time to live
	TTL (key string) (duration time.Duration, err error)
	// Set key to hold a string value and to timeout after a given time.Duration
	SetEx(key, val string, duration time.Duration) error
	// Extend a key's living time duration before timeout
	ExtendKey(key string, duration time.Duration) error
	// Delete a key
	DelKey(key string) error
}

About

a wrapper of dgrijalva/jwt-go with storage interface

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published