Comments (11)
See passport-facebook-token, which implements this as a Passport strategy.
from passport-facebook.
+1 encountering the same issue too
from passport-facebook.
+1
from passport-facebook.
+1 on this too
from passport-facebook.
I have a single page application. It does not use cookies. Instead I use access_token with the requests that need authentication. This access_token is alpha-numeric string long 40 chars and valid only for 1 hour. In order to use Facebook auth I need to click a "login with facebook" button which leads to http://api.mydomain.com/auht/facebook. Then when the facebook callback is called my API generates a token and needs to send this token to the client somehow.
Right now I'm redirecting to the client to a parametrized URL like this one /#/auth/:token so that the client can get the token and from that point on make authentic requests to the API server. I don't like this solution. My app is still in development mode and I would like to release it in production with a better way of giving the token to the client.
-Pavel
from passport-facebook.
@pavelnikolov Your solution works but, as you mention, is kind of a hack.
After digging into this strategy I took a step back and realised that it's a pure OAuth 2.0 wrapper. Aside from the Facebook JavaScript SDK client-side authentication.
Using the Facebook client-side accessToken
(short lived) it's not possible to login the user (via XHR) without the redirect that OAuth 2.0 enforces. I've implemented this in a project simply by using the req.login
method after verifying the token and fetching user data from Facebook.
Conclution: Client-side authentication via the Facebook JavaScript SDK is not a natural feature of this strategy and should be defined as a separate Passport strategy.
from passport-facebook.
Thank you for your reply - I knew there should be a better way. I haven't used that so far. Can you point me to a link to some documentation or examples?
from passport-facebook.
@pavelnikolov Using Express, Mongoose and FBgraph, this is a simplified example of a POST
controller:
graph.setAccessToken(req.body.accessToken);
graph.get('me?fields=id,email,name', function(err, data) {
if(err) return res.json(400, err);
User.findOne({'facebook.id': data.id}, function(err, user) {
if(err) return res.json(400, err);
if(!user) {
// First login, create user object..
// Then login the user
req.login(user, function(err) {
if(err) return res.json(400, err);
res.json(user);
});
}
else {
// User found, update user object..
// Then login the user
req.login(user, function(err) {
if(err) return res.json(400, err);
res.json(user);
});
}
});
});
from passport-facebook.
Thank you. I will try this for sure.
from passport-facebook.
The solutions here look good for facebook token authentication, but is there one for google? Google also provides a client side API method for getting an access token:
https://developers.google.com/+/web/signin/javascript-flow
from passport-facebook.
@etler Sure, using the same approach would work fine. See https://developers.google.com/+/web/signin/client-to-server-flow
from passport-facebook.
Related Issues (20)
- how to enable enable_profile_selector ?
- FacebookStrategy function is not working HOT 1
- Does passport-facebook work with https://github.com/facebook/react-native-fbsdk to retrieve refresh token?
- Logout_issue
- what if the user has multiple accounts on facebook and wanna switch to another account
- Hello HOT 1
- The re authenticate not working HOT 6
- i am getting an error of status code 500 from facebook
- Session Expired when using Passportjs Facebook from Facebook App in IOS HOT 1
- Hello
- Passport Facebook not redirecting correctly (Error Code 500) HOT 2
- instagram_basic permission getting ignored
- Warning Can't Load URL: HOT 2
- I am facing such issue anyone help me
- Facebook has detected that Secret isn't using a secure connection to transfer information.
- facebook login error : Sorry, something went wrong. We're working on getting this fixed as soon as we can. HOT 1
- FacebookToken Error via localhost HOT 2
- E11000 duplicate key error collection HOT 1
- Facebook allow Email scope not working, It's not return "email" ? HOT 4
- Lastest Facebook Version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from passport-facebook.