Skip to content

Commit

Permalink
Fixed setAccessExpiresIn method.
Browse files Browse the repository at this point in the history
Summary:
There are two types of access tokens:
 - ones that doesn't expire (expiresIn == 0)
 - ones that have some expiration period( (expiresIn > 0)
When we receive a new token from FB server for both them we call the
setAccessExpiresIn method.
Because of that:
1. We shouldn't ignore the "0" value
2. We should also expect tokens that have long expiration period.
For example 60 days is 2592000000000 miliseconds which is too much for an
integer variable to handle :)

Test Plan: Tried Login In / Logout for both types of tokens.

Reviewers: jimbru, yariv

Reviewed By: jimbru

CC: kamil, jimbru

Differential Revision: 370353
  • Loading branch information
Kamil Kraszewski authored and Kamil Kraszewski committed Dec 1, 2011
1 parent 61551e0 commit 50e4fd5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions facebook/src/com/facebook/android/Facebook.java
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,7 @@ public long getAccessExpires() {
/**
* Set the OAuth 2.0 access token for API access.
*
* @param token
* - access token
* @param token - access token
*/
public void setAccessToken(String token) {
mAccessToken = token;
Expand All @@ -670,23 +669,25 @@ public void setAccessToken(String token) {
* Set the current session's expiration time (in milliseconds since Unix
* epoch), or 0 if the session doesn't expire.
*
* @param time
* - timestamp in milliseconds
* @param time - timestamp in milliseconds
*/
public void setAccessExpires(long time) {
mAccessExpires = time;
}

/**
* Set the current session's duration (in seconds since Unix epoch).
* Set the current session's duration (in seconds since Unix epoch), or "0"
* if session doesn't expire.
*
* @param expiresIn
* - duration in seconds
* - duration in seconds (or 0 if the session doesn't expire)
*/
public void setAccessExpiresIn(String expiresIn) {
if (expiresIn != null && !expiresIn.equals("0")) {
setAccessExpires(System.currentTimeMillis()
+ Integer.parseInt(expiresIn) * 1000);
if (expiresIn != null) {
long expires = expiresIn.equals("0")
? 0
: System.currentTimeMillis() + Long.parseLong(expiresIn) * 1000L;
setAccessExpires(expires);
}
}

Expand Down

0 comments on commit 50e4fd5

Please sign in to comment.