Permalink
Browse files

Fixed setAccessExpiresIn method.

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 Kamil Kraszewski
Kamil Kraszewski authored and Kamil Kraszewski committed Dec 1, 2011
1 parent 61551e0 commit 50e4fd5493371cdb641b304eda81253577e00381
Showing with 10 additions and 9 deletions.
  1. +10 −9 facebook/src/com/facebook/android/Facebook.java
@@ -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;
@@ -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);
}
}

0 comments on commit 50e4fd5

Please sign in to comment.