In my app, I'm trying to authenticate (login) by passing Facebook session information (token and expiration date) to my server.
My login sequence to the app server is as follows:
- Get active facebook session.
- If the session is valid, get token and send it on to the server.
And in code:
Session session = Session.getActiveSession();
if(session != null && session.isOpened() && !didLogin) {
didLogin = true;
String token = session.getAccessToken();
Date expires = session.getExpirationDate();
loginWithFacebookSession(token, expires);
}
I have noticed that suddenly, after a few months of this working just fine, the information being sent to the server is occasionally not valid, specifically the token
is an empty string and the expires
is an invalid date.
After going a bit through the Facebook SDK (version 3.0.1), I spotted what is probably the basis of my error:
private static final Date MIN_DATE = new Date(Long.MIN_VALUE);
private static final Date ALREADY_EXPIRED_EXPIRATION_TIME = MIN_DATE;
private static final Date DEFAULT_LAST_REFRESH_TIME = new Date();
static AccessToken createEmptyToken(List<String> permissions) {
return new AccessToken("", ALREADY_EXPIRED_EXPIRATION_TIME, permissions, AccessTokenSource.NONE,
DEFAULT_LAST_REFRESH_TIME);
}
This means that somewhere along the way, the Facebook SDK is creating an empty token and returning it with a SessionState.Category.OPENED_CATEGORY
.
Why is session.isOpened()
returning true
when in fact there is no accessToken
information? Should I be checking a different property? Is this a bug in Facebook's SDK?
EDIT:
Reported this to Facebook at: https://developers.facebook.com/bugs/121924628017965
UiLifecycleHelper
class as documented in the Facebook developers website – Audry