angular - Auth0 用户信息方法返回仅具有子属性的用户对象

标签 angular authentication auth0

我正在为我的 Angular 应用程序构建身份验证,并且当有人登录时我试图从 auth0 获取用户信息。我使用 auth0 文档作为指导,我得到了“用户”对象,但它只有子属性,没有名称、电子邮件等。

Object {sub: "auth0|5**********7"}

我尝试使用 facebook、linkedin、google 登录并在没有社交媒体的情况下注册,但结果是相同的,只是“auth0 |”部分变化。这是我的 auth.service.ts :

auth0 = new auth0.WebAuth({
  clientID: 'myClientID',
  domain: 'myDomain.auth0.com',
  responseType: 'token id_token',
  audience: 'https://myDomain.auth0.com/userinfo',
  redirectUri: 'http://localhost:4200/',
  scope: 'openid'
})

handleAuthentication(): void {
  this.auth0.parseHash((err, authResult) => {
    if (authResult && authResult.accessToken && authResult.idToken) {
      window.location.hash = '';
      this.setSession(authResult);
      this.router.navigate(['/dersler']);

      // This is for getting user info after authentication (taken from the auth0 docs but revised)
      this.auth0.client.userInfo(authResult.accessToken, function(err, user) {
      // This method will make a request to the /userinfo endpoint 
      // and return the user object, which contains the user's information, 
        if (err) {
          return console.log(err);
        }
        console.log(user);
        return;
      });
      // method to get user info ends here

    } else if (err) {
      this.router.navigate(['/']);
      console.log(err);
    }
  });
}

我尝试在 auth0 文档中使用 http 方法获取用户信息,但它仅使用“sub”属性返回相同的用户对象。为什么它不返回其他用户信息?

编辑(已解决): 我将 auth0 的“范围”属性从“openid”更改为“openid 配置文件”,现在它成功返回包含名称和所有其他信息的用户对象。

最佳答案

问题出在您的 scope 参数中,您可以将其更改为 scope: 'openid profile email phone'。然后注销,登录即可完成。

更多信息here

关于angular - Auth0 用户信息方法返回仅具有子属性的用户对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44091046/

相关文章:

javascript - 验证传入的请求

C#/ASP.NET/AD - "The specified directory service attribute or value does not exist."

iOS NSURLRequest 以编程方式登录网站

php - Symfony 4.4 Auth0如何从应用程序中完全注销用户

authentication - KeyCloak 应该用作我的用户的身份验证服务器吗?

angular - 试图理解此代码 : map((data: SearchResponse) => data && data. 项目 || [])

angular - 按 Enter 调用 click 方法中的代码

angular - 如何在 iframe 上使用 Auth0 登录

angular - 设置路线时在 Angular 2中使用名称

Angular 如何在服务中使用 Websocket?