我找不到如何从 Auth0 身份验证 api 获取 user_metadata:
$auth0Api = new Authentication($domain, $clientId, $clientSecret);
$tokenInfo = $auth0Api->login([
'username' => $username,
'password' => $password,
'realm' => 'Username-Password-Authentication',
]);
$accessToken = $tokenInfo["access_token"];
$info = $auth0Api->userinfo($accessToken);
最后的$info
数组只包含主要的用户信息,根本没有meta_data。我尝试从 Auth0 端创建规则以向用户本身添加内容(例如,执行 user.customtag = 'helloworld'
)并且自定义项也没有显示。
检索到的用户信息:
{
"sub":"auth0|XXXX",
"name":"XXXX@XXXX.com",
"nickname":"XXXX",
"picture":"XXXX.png",
"updated_at":"2017-03-31T08:50:59.819Z",
"email":"XXXX@XXXX.com",
"email_verified":true
}
该用户的“原始 Json”选项卡显示了更完整的内容:
{
"email": "XXXX@XXXX.com",
"email_verified": true,
"user_id": "auth0|XXXX",
"picture": "XXXX.png",
"nickname": "XXXX",
"identities": [
{
"user_id": "XXXX",
"provider": "auth0",
"connection": "Username-Password-Authentication",
"isSocial": false
}
],
"updated_at": "2017-03-31T08:50:59.819Z",
"created_at": "2017-03-23T16:03:47.075Z",
"name": "XXXX",
"user_metadata": {
"languageCode": "EN"
},
"last_ip": "XXXX",
"last_login": "XXXX",
"logins_count": XXXX,
"blocked_for": [],
"guardian_enrollments": []
}
它应该如何工作?
环境:
- Composer :“auth0/auth0-php”:“~5.0”
- php 7.1
- Auth0 免费帐户
最佳答案
尝试在本地启动您的应用程序,然后使用您自己的设置更新以下 URL 并将其粘贴到网络浏览器中:
https://YOUR_TENANT.auth0.com/authorize?client_id=YOUR_CLIENT_ID&response_type=code&scope=openid profile&redirect_uri=YOUR_REDIRECT_URI&nonce=12345
这至少应该确保您在正确的范围内发出请求等。如果您希望在身份验证后阅读该数据,您还应该确保您拥有分配了一些“元数据”的用户配置文件 ;)
关于php - 获取 auth0 用户元数据作为用户信息的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43118021/