好的,我刚遇到了一个问题。我正在使用Auth0在App Metadata中创建具有不同权限(不仅仅是作用域权限)的用户。当我解码令牌时,我得到了这个json:
{
"iss": "https://testing.auth0.com/",
"sub": "auth0|58e7bae154941844b507eaf5",
"aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
"exp": 1497016797,
"iat": 1496980797,
"https://thetestgroup.com/app_metadata": {
"is_admin": true
}
}
正如您所见,应用元数据位于元素" https://thetestgroup.com/app_metadata"中。通常我会在我的代码(auth.payload.iat)中执行类似这样的操作来获取iat,但是对于app_metadata,它拒绝它,因为:。有没有一种很好的方法来获取这些数据?
答案 0 :(得分:-1)
好吧,让我们谈谈javascript(节点)和你的json
Firefox Scratchpad(Shift-F4)
var x = {
"iss": "https://testing.auth0.com/",
"sub": "auth0|58e7bae154941844b507eaf5",
"aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
"exp": 1497016797,
"iat": 1496980797,
"https://thetestgroup.com/app_metadata": {
"is_admin": true
}
}
x['https://thetestgroup.com/app_metadata'].is_admin // hit run
/*
true
*/
的node.js
~ $ node -v
v8.1.0
~ $ node
> var x = {
... "iss": "https://testing.auth0.com/",
... "sub": "auth0|58e7bae154941844b507eaf5",
... "aud": "OSBkLd832tIhpDe0QFJbQ9vutgB2s6cJ",
... "exp": 1497016797,
... "iat": 1496980797,
... "https://thetestgroup.com/app_metadata": {
..... "is_admin": true
..... }
... }
undefined
> x['https://thetestgroup.com/app_metadata'].is_admin
true
>
请提供mcve,因为纯JS和JSON非常乐意使用(奇怪)密钥 - 如图所示。