Facebook IOS authentication using node.js passport-facebook-token

I am trying to authenticate in node.js api using passport-facebook-token from an iOS application.

I have a username and password setting, as well as full work with a passport and setting a passport-facebook-token in accordance with the example.

passport.use(new FacebookTokenStrategy({ clientID: config.facebook.clientID, clientSecret: config.facebook.clientSecret }, function(accessToken, refreshToken, profile, done) { User.findOrCreate({ facebookId: profile.id }, function (err, user) { return done(err, user); }); 

I just can't understand the HTTP request syntax needed to send an access token to the API.

Any help would be greatly appreciated.

Thanks.

+6
source share
2 answers

OK managed to generate an answer from the strategy file from the passport-facebook-token

This requires:

http: // url? access_token = [access token]

From iOS, I just tested this with:

 NSString *fbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken]; NSLog(@"This is token: %@", fbAccessToken); NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://myapi.url.com/auth/facebook?access_token=%@",fbAccessToken]]; NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url]; [req setHTTPMethod:@"GET"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSURLResponse *res; NSError *err; [NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err]; if (!err) { NSLog(@"The user is logged in on the server side too"); } else { NSLog(@"Error occurred. %@", err); } }); 

Hope this helps someone else.

+18
source

You can also do this with a header. Curl for this

 curl localhost:3000/endpoint -H "Authorization: Bearer <facebook token>" 
0
source

Source: https://habr.com/ru/post/952910/


All Articles