下面是后端用于生成jwt-token的函數(shù)(golang寫的),會(huì)返回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接收到j(luò)wt-token,怎么解析出jwt-token中的username?
前后端分離項(xiàng)目,前端javascript怎么解析出jwt-token中的username?
慕斯709654
2019-01-30 10:17:03