草庐IT

chkRoles

全部标签

json - 如何检查 JWT 的角色声明(值数组)的某个值?

我正在使用Golang和Gin框架从客户端发送的JWT中获取声明。但我无法将提取的角色与字符串进行比较。当我尝试获取值时,它返回[test-app]但实际上我想要的值是"test-app"token,_,err:=new(jwt.Parser).ParseUnverified(tokenString,jwt.MapClaims{})iferr!=nil{fmt.Println(err2)return}ifclaims,ok:=token.Claims.(jwt.MapClaims);ok{chkRoles:=claims["roles"]ifchkRoles=="test-app"{f

json - 如何检查 JWT 的角色声明(值数组)的某个值?

我正在使用Golang和Gin框架从客户端发送的JWT中获取声明。但我无法将提取的角色与字符串进行比较。当我尝试获取值时,它返回[test-app]但实际上我想要的值是"test-app"token,_,err:=new(jwt.Parser).ParseUnverified(tokenString,jwt.MapClaims{})iferr!=nil{fmt.Println(err2)return}ifclaims,ok:=token.Claims.(jwt.MapClaims);ok{chkRoles:=claims["roles"]ifchkRoles=="test-app"{f