gopkg.in/jwt.v1
go get gopkg.in/jwt.v1

gopkg.in/jwt.v1

an JSON Web Tokens (JWT) project for golang

by go-jwt

v1.0.7 (see all)License:MIT
go get gopkg.in/jwt.v1
Readme

做中国最好的JWT包

How to use it?

获取包

go get -u gopkg.in/jwt.v1

Example:

//获取一个claims
claims := NewClaims()
//注册一个域名
claims.RegisterAud("example.com", "api.example.com")

/*
"iss": "https://server.example.com",
"sub": "24400320",
"aud": "s6BhdRkqt3",
"nonce": "n-0S6_WzA2Mj",
"exp": 1311281970,
"iat": 1311280970,
"auth_time": 1311280969,
"acr": "urn:mace:incommon:iap:silver"
*/
    //上面的数据串可以通过如下方式注册
claims.RegisterIss("https://server.example.com")
claims.RegisterSub("24400320")
claims.RegisterExp(time.Now())
claims.RegisterIat(time.Now())

//获取数据串
claims.IssuedAt()
claims.Subject()
claims.Expiration() // or claims.ExpirationTime()
claims.IssuedAt()   

//自定义一个string的acr值
claims.Register("acr","urn:mace:incommon:iap:silver")
claims.Register("nonce","a string value")
//传入一个time类型
claims.RegisterByTime("auth_time",time.Now())


//创建一个header
header := NewHeader() // or NewJWTHeader
header.Register(HEADER_TYPE, "JWT")
//指定压缩方式
header.Register(HEADER_ALGORITHM, "HS256")
//或者
header := DefaultHeader()

//使用claims,header,key 来创建token
token := NewToken(claims, header, "abcdef")

    //使用序列化token用于传输
serializedToken, _ := token.Serialize()



    //当接受到一串序列化token时:
//通过key和序列化token,反序列化得到token
newToken, _ := ParseToken(serializedToken, "abcdef")

    //获取claims
newToken.Claims()
//获取header
newToken.Header()

//验证claims
claims.Validate(newToken)

GitHub Stars

11

LAST COMMIT

4yrs ago

MAINTAINERS

0

CONTRIBUTORS

2

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v1.0.2
3yrs ago
v1.0.0
3yrs ago
v1.0.4
3yrs ago
v1.0.5
3yrs ago
No alternatives found
No tutorials found
Add a tutorial