I'm trying to authenticate to a node.js API using passport-facebook-token from an IOS app.
I have username and password auth set-up and working fine through passport and the passport-facebook-token set-up as per 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 figure out the HTTP request syntax needed to send the access token across to the API.
Any help would be massively appreciated.
OK managed to work out the answer from the strategy file from passport-facebook-token
It requires:
http://URL?access_token=[access token]
From IOS i simply 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.