Facebook cached token after user revokes app permissions returns wrong
session state
I'm using the latest Facebook SDK for iOS (v3.7.1) and I'm having
something confusing happen:
I launch my app, click "Sign into Facebook" and authorize my app
I close my app and goto Facebook where I revoke access to my app
I launch my app again, click "Sign into Facebook" and the app says that it
found a cached token
When I call [FBSession.activeSession openWithCompletionHandler... it
returns that the session is in the FBSessionStateOpen state even though
the session should really be in the FBSessionStateClosed state
Why would Facebook return an invalid state for the cached token? I thought
that was the whole point of using openWithCompletionHandler to check if
the cached token was still valid or not.
I am checking the token status when they click the sign in button:
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
NSLog(@"We have a cached token, so we're going to re-establish the
sign in for the user.");
// Even though we had a cached token, we need to sign in to make the
session usable
// This should happen in the background without having to present any
UI to the user
[FBSession.activeSession openWithCompletionHandler:^(FBSession
*session, FBSessionState status, NSError *error) {
[self handleResponseForFacebookSession:session status:status
error:error];
}];
} else {
// If the token is currently open or an extended token, then we an go
ahead and use it
}
This is the response handler:
// Handles the response from the FBSession open session completion handler
- (void)handleResponseForFacebookSession:(FBSession *)session
status:(FBSessionState)status error:(NSError *)error
{
NSLog(@"Received: %@\nStatus: %u\nError: %@", session, status, error);
switch (status) {
case FBSessionStateOpen:
// We should sign in
break;
case FBSessionStateClosed:
[self authenticateWithFacebook];
NSLog(@"The Facebook session has been closed (maybe they took
access away) so we need to ask the user to login again");
break;
case FBSessionStateClosedLoginFailed:
[self handleFacebookError:error];
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
[self handleFacebookError:error];
NSLog(@"We received an unrecognized status while opening a
Facebook session (%@): %u", session, status);
break;
}
}
No comments:
Post a Comment