无法在iOS Facebook SDK中将access_tokenvalidation为PassportJS
我正在尝试使用Facebook iOS sdk与PassportJS(服务器是NodeJS)我成功地设法在我的iOS应用程序上使用Facebooklogin。 接下来我要做的是将访问令牌移交给服务器,并从那里进行validation。 不幸的是它根本不起作用。
怪异的部分是,我的网站,它工作正常。 我只是使用callbackURL将令牌发布到服务器。
所以在代码中,Facebooklogin后会发生什么(工作)
/* * Callback for session changes. */ - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error { switch (state) { case FBSessionStateOpen: if (!error) { // We have a valid session NSString *token = session.accessTokenData.accessToken; NSLog(@"User session found: %@", token); [[NSNotificationCenter defaultCenter] postNotificationName:nGotFacebookSession object:nil userInfo:@{ @"token": token }]; } break; case FBSessionStateClosed: case FBSessionStateClosedLoginFailed: [FBSession.activeSession closeAndClearTokenInformation]; break; default: break; } [[NSNotificationCenter defaultCenter] postNotificationName:FBSessionStateChangedNotification object:session]; if (error) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } }
然后,在login控制器中收到通知:
- (void) facebookLogin: (NSNotification*) notification { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; NSString *token = [notification.userInfo objectForKey:@"token"]; [[CBApi sharedAPI] get:@"api/auth/facebook/callback" andParams:@{ @"code": token } andCallback:^(NSDictionary *json) { [MBProgressHUD hideHUDForView:self.view animated:YES]; if ([json objectForKey:kError]) { Alert(@"Error", @"Login details failed"); } else { User *u = [User createEntity]; u.email = self.emailField.text; [self dismissViewControllerAnimated:YES completion:nil]; } }]; }
然后我从服务器得到这个错误(从控制台copypasted):
failed to obtain access token (status: 400 data: { "error": { "message": "Invalid verification code format.", "type": "OAuthException", "code": 100 } })
就像我说的,它使用网站login时没有问题,它只是不接受iOS本地生成的访问令牌。 我以前从来没有做过像这样的fblogin。 如果你能帮助我,这将是非常好的,谢谢!
我想到了! 对于任何有同样问题的人,这就是我所做的:不要使用passportjs的正常Facebook策略,而是使用这个: https : //github.com/drudge/passport-facebook-token
它允许你使用主动访问令牌,几乎是替代我的下降。 服务器为网站使用旧的Facebook策略(与passpostjs一起来的人)以及用于iOSlogin的facebook策略令牌。
- Facebook Messenger bot不按顺序发送消息
- Mongoose schematype.castForQuery错误。 用户身份validation失败
- 使用PassportJS和NodeJS的Connect来validationFacebook用户
- nodejs护照 – 脸书authentication
- Facebook营销API:Param必须是有效的Instagram帐户ID
- 什么是node.js最好的facebook连接库?
- FacebookTokenError:这个授权码已被使用
- MEAN堆栈Facebook授权错误:没有“访问控制允许来源”标题?
- 张贴到Facebook错误:'(#200)用户没有授权应用程序执行此操作',键入:'OAuthException',代码:200