1
votes

I am using Ember CLI + ember simple auth torii link

to get authentication code from facebook for my ember app.

This is my environment.js file

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 -

<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.

How do I get the user's email id along with this token ? Has anybody faced a similar issue ?

1

1 Answers

2
votes

So you're using oauth2, so all you're ever going to get is an authorization token. 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.