2017-05-20 8 views
1

私のアングルアプリケーションの認証を作成しています。ユーザーがログインしたときにauth0からuserinfoを取得しようとしています。私は指導としてauth0のドキュメントを使用していると私は「ユーザー」オブジェクトを取得しますが、それには名前、電子メールをのみ、サブプロパティを持っていないなどAuth0のユーザー情報メソッドは、サブプロパティーのあるユーザーオブジェクトを返します

Object {sub: "auth0|5**********7"} 
私はLinkedInの、ログインをグーグル、フェイスブックにしようとしたソーシャルメディアずにサインアップし

結果は同じです '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メソッドとuserinfoを取得しようとしたが、それだけで「サブ」プロパティと同じユーザオブジェクトを返します。他のユーザー情報が返されないのはなぜですか?

EDIT(SOLVED): auth0の 'scope'プロパティを 'openid'から 'openid profile'に変更しました。これで、名前とその他すべての情報を含むユーザーオブジェクトが正常に返されます。

答えて

3

問題がscopeパラメータにある場合は、scope: 'openid profile email phone'に変更できます。その後、ログアウトしてログインしてください。

詳細情報here

+0

あなたを保存しました!私たちの2人は2日かかりました。私はこれを見て、それを理解しました。あなたは英雄です、ありがとう! –

関連する問題