我在我的react应用程序中用jwt-decode解码一个jwt令牌,但是我无法从中获得claims参数,我怎么能得到这些呢?例如,我将从理赔对角处得到角色。
这是我的解码令牌结果:
{
aud: "SampleAudience"
exp: 1564989998
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "SuperAdministrators"
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress": "sso_khani"
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "sso_khani"
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "ab57e777-91b6-4c4e-d709-08d715866555"
iss: "threenine.co.uk"
}发布于 2019-08-05 10:04:17
您可以要求后端团队在定义的键名中提供值。你还是可以做的,
Object.keys(decodedObj).forEach(function (key) {
let res = key.split("/");
if (res.length > 1) {
if (res[length - 1] === 'role') {
// decodedObj[key] will be your role
}
// here you will get role, emailaddress, name, nameidentifier
}
});如果这有帮助的话请告诉我。
发布于 2022-11-08 10:22:31
decodedOBj"http://schemas.microsoft.com/ws/2008/06/identity/claims/role“应该返回SuperAdministrators等。
https://stackoverflow.com/questions/57353664
复制相似问题