【问题标题】:How to get a username from response object using Auth0 Lock?如何使用 Auth0 Lock 从响应对象中获取用户名?
【发布时间】:2019-09-11 17:23:10
【问题描述】:

问题是如何从响应对象中获取我用来登录的用户名?

我正在通过以下代码创建 Auth0Lock 实例:

this._lock = new Auth0Lock(AUTH_CONFIG.clientId, AUTH_CONFIG.domain, AUTH_CONFIG.options);

然后我订阅“已验证”事件:

this._lock.on('authenticated', authResult => {
  this._lock.getUserInfo(authResult.accessToken, function(error, profile) {

        console.log('profile', profile); // --> undefined

        if (error) {
          // Handle error
        }

  });
})

我正在使用以下凭据登录:

用户名:john@gmail.com 密码:123456

我希望能够在 authResult 对象的某处看到“用户名:john@gmail.com”。 但很遗憾我没有看到。

我应该在 Auth0lock 选项中添加一些东西吗?

附:我在“已验证”事件的处理程序中添加了以下代码,但它返回未定义的配置文件。

【问题讨论】:

  • 查看文档的第 2 步:auth0.com/docs/libraries/lock/v11
  • 当我调用 this.getUserInfo(authResult.accessToken, function(error, profile){ console.log('profile', profile) }) 我收到错误:Uncaught TypeError: _this2 .getUserInfo 不是函数

标签: javascript angularjs reactjs authentication auth0


【解决方案1】:

我刚刚将 scope: 'openid' 添加到选项的“auth”属性中

options: {
  ...
  auth: {
    ...
    scope: 'openid'  <---
  }
}

【讨论】:

    猜你喜欢
    • 2019-03-13
    • 2021-11-24
    • 2017-06-02
    • 2017-10-05
    • 2019-04-01
    • 2017-04-11
    • 2018-01-11
    • 1970-01-01
    • 2017-03-28
    相关资源
    最近更新 更多