pc035860 / angular-easyfb

Super easy AngularJS + Facebook JavaScript SDK.
MIT License
440 stars 69 forks source link

Load access token into API #38

Open nivek91 opened 10 years ago

nivek91 commented 10 years ago

Hi after the user has signed in with facebook. I have result with the access token and the user id. I was trying to pass these 2 things to the ezfb object so the user doesn't have to sign in with facebook again. Is there a way to do this?

My code for login: ezfb.login(null, { scope: facebookcfg.scope }).then(function(res) { console.log(res); $facebook.saveFacebookToken(res.authResponse.accessToken, res.authResponse.userID); }); I want to do this:

$facebook.getFacebookToken() .then(function(result) { //TODO: pass result to ezfb: ezfb.loadSignedInData(result.accesstoken, result.userId) console.log(result); }, function(result) { $scope.login(); })

Thanks!

pc035860 commented 10 years ago

Hi @nivek91 ,

In my understanding, you can use Facebook JS SDK to do what you're attempting to do without saving the access token (Facebook itself doesn't want you to do that either).

Once the user gets connected with your Facebook application and doesn't manually remove the connection, you can simply use ezfb.getLoginStatus() to check for user's connection with your application and start the login process from there.

You can check out the API demo in README.md as an example.

nivek91 commented 10 years ago

Hey, first thanks for replying!

I think I was not very clear!

The flow would be like this: user enters to web site, sign in with facebook credentials (fb user, fb pass) > response with access token, user id (token: eeab2, user id: 521) > web site stores access token, user id > web site calls facebook API, for example get friends. > user leaves the web site and closes browser. Same user enters to web site, I don't want him to sign in with facebook credentials again, I just want to call the api because he had already signed in, so I get the access token, user id from my back end, but I don't know how to send this data to the facebook api to be able to call the api without signing in again.

Kevin

On Sun, Aug 24, 2014 at 3:03 AM, Chih-Hsuan Fan notifications@github.com wrote:

Hi @nivek91 https://github.com/nivek91 ,

In my understanding, you can use Facebook JS SDK to do what you're attempting to do without saving the access token (Facebook itself doesn't want you to do that either).

Once the user gets connected with your Facebook application and doesn't manually remove the connection, you can simply use ezfb.getLoginStatus() to check for user's connection with your application and start the login process from there.

You can check out the API demo http://plnkr.co/edit/qclqht?p=preview in README.md as an example.

— Reply to this email directly or view it on GitHub https://github.com/pc035860/angular-easyfb/issues/38#issuecomment-53172897 .

wmbutler commented 9 years ago

Any headway on this? I'd like the same thing. I just want to be able to send the fb token with the request.

pc035860 commented 9 years ago

Hey @wmbutler

As long as the user has signed in Facebook and already connected with your FB application.

Simply call .getLoginStatus() before calling .api(), usually you won't have to pass the credentials to FB JS SDK, the JS SDK can share the login status with back-end SDKs with cookie: true parameter.

e.g. http://plnkr.co/edit/qclqht?p=preview

It doesn't require you to login in with Facebook again before calling .api('/me').