简体   繁体   English

Ember Torii Facebook身份验证无法获取用户电子邮件

[英]Ember Torii facebook authentication not able to get user email

I am using Ember CLI + ember simple auth torii link 我正在使用Ember CLI + ember简单身份验证torii 链接

to get authentication code from facebook for my ember app. 从facebook获取我的余烬应用程序的身份验证代码。

This is my environment.js file 这是我的environment.js文件

ENV['torii'] = {
    providers: {
      'facebook-oauth2': {
        apiKey:      '865549306850377',
        scope: 'email',
        //redirectUri: window.document.location.href
        redirectUri: 'http://localhost:4200/'
      }
    }
  };

And my login controller looks like this - 我的登录控制器看起来像这样-

facebook: function() {

    var _this = this;
            this.get('session').authenticate('simple-auth-authenticator:torii', 'facebook-oauth2').then(function(data){
                console.log("status - ", _this.get('session'));
            });
        }

And login.hbs - 和login.hbs-

<li><button {{action "facebook" "facebook-oauth2"}}>Facebook OAuth2</button></li>

After the user clicks on the link, a facebook popup opens and ember app gets a token. 用户单击链接后,将打开一个Facebook弹出窗口,并且ember应用程序将获得令牌。

How do I get the user's email id along with this token ? 如何获得用户的电子邮件ID以及此令牌? Has anybody faced a similar issue ? 有人遇到过类似的问题吗?

So you're using oauth2, so all you're ever going to get is an authorization token. 因此,您使用的是oauth2,因此您将获得的只是授权令牌。 With this token, you can then go off and request other information. 使用此令牌,您可以随后请求其他信息。 The token is basically just there to speed up the validation of users against your application. 令牌基本上就在那里,以加快针对您的应用程序的用户验证。

If you want to get user information, you would need to create another method (probably on your server-side), which swaps the authorization code for an access token: like so (or alternatively you can request an access token directly, which would remove the need for a server-side solution. 如果要获取用户信息,则需要创建另一个方法(可能在服务器端),该方法将授权代码交换为访问令牌: 像这样 (或者,您可以直接请求访问令牌,这将删除对服务器端解决方案的需求。

Using the access Token you can then request the Facebook User ID, using the debug token endpoint , and after that you will be able get to any endpoint to get the information you need. 然后, 使用访问令牌,您可以使用调试令牌终结点来请求Facebook用户ID,之后,您将可以访问任何终结点来获取所需的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM