JWT

简介

json web token

基础示例

使用Jwt必须先实现签发者接口

JwtAudience interface {
        Audience() string
}

创建Jwt实例

var    (
    jwtConfig = config.Item("jwt")
  memoryStore = jwt.NewMemoryStore()
)

// 创建jwt
jwt := New("secret", jwtConfig, memoryStore)

假设有User实现JwtAudience

生成token

解析token

验证token

其它方法

自定义存储器

系统默认自带内存存储器,通常在分布式应用中你需要其它存储引擎,实现起来也非常简单,只需要实现JwtStore 接口,如下示例:

Last updated

Was this helpful?