IOS Facebook身份验证使用node.js passport-facebook-token

pop*_*rob 6 api node.js ios passport.js

我正在尝试使用来自IOS应用程序的passport-facebook-token对node.js api进行身份验证.

我有用户名和密码验证设置,并通过护照和护照-facebook-token设置正常工作.

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);
});
Run Code Online (Sandbox Code Playgroud)

我只是无法弄清楚将访问令牌发送到API所需的HTTP请求语法.

任何帮助都将受到大力赞赏.

谢谢.

pop*_*rob 18

确定设法从passport-facebook-token的策略文件中找出答案

这个需要:

http:// URL?access_token = [访问令牌]

从IOS我只是用以下方法测试:

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);
}
});    
Run Code Online (Sandbox Code Playgroud)

希望这有助于其他人.