获取auth0用户元数据作为用户信息的一部分

时间:2017-03-30 12:33:59

标签: php auth0

我没有找到如何从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
}

" Raw 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": []
}

它应该如何运作?

环境:

  • 作曲家:" auth0 / auth0-php":" ~5.0"
  • php 7.1
  • Auth0免费帐户

1 个答案:

答案 0 :(得分:0)

尝试在本地启动您的应用,然后使用您自己的设置更新以下网址并将其粘贴到网络浏览器中:

https://YOUR_TENANT.auth0.com/authorize?client_id=YOUR_CLIENT_ID&response_type=code&scope=openid profile&redirect_uri=YOUR_REDIRECT_URI&nonce=12345

这至少应该确保您使用正确的范围等来发出请求。如果您希望在认证后阅读该数据,您还应该确保您拥有分配了一些“元数据”的用户配置文件;)