下面是后端用于生成jwt-token的函数(golang写的),会返回jwt-token给前端,里面包含username:
// Sign signs the context with the specified secret.func Sign(ctx *gin.Context, c Context, secret string) (tokenString string, err error) { // Load the jwt secret from the Gin config if the secret isn't specified.
if secret == "" {
secret = viper.GetString("jwt_secret")
} // The token content.
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ "id": c.ID, "username": c.Username, "nbf": time.Now().Unix(), "iat": time.Now().Unix(),
}) // Sign the token with the specified secret.
tokenString, err = token.SignedString([]byte(secret)) return}问题:
前端javascript接收到jwt-token,怎么解析出jwt-token中的username?
慕斯709654
慕村225694
随时随地看视频慕课网APP
相关分类