Permalink
Browse files

Merge branch 'releasecandidate/0.4.8'

  • Loading branch information...
2 parents d2404d6 + 82f0297 commit a915944f7990c71e4c7388fe59a485676e1116e8 Benoit Hediard committed Jan 3, 2013
View
2 FacebookSdkGrailsPlugin.groovy
@@ -2,7 +2,7 @@ import grails.plugin.facebooksdk.*
class FacebookSdkGrailsPlugin {
- def version = "0.4.7"
+ def version = "0.4.8"
def grailsVersion = "2.0 > *"
def author = "Benoit Hediard"
View
4 README.md
@@ -34,7 +34,7 @@ grails.project.dependency.resolution = {
}
plugins {
//here go your plugin dependencies
- runtime ':facebook-sdk:0.4.7'
+ runtime ':facebook-sdk:0.4.8'
}
}
```
@@ -75,6 +75,8 @@ Project documentation is located here :
WARNING: Since V0.4.0, _FacebookApp_, _FacebookSdkFilters_ and _FacebookAppService_ from V0.3.* are DEPRECATED and have been replaced by _FacebookContext_.
Please check [FacebookContext](http://benorama.github.com/grails-facebook-sdk/guide/facebookContext.html) doc for more info.
+* 2013-01-03 **V0.4.8** : bug fix token expiration time handling (in Facebook Page tabs)
+* 2012-12-20 **V0.4.7** : bug fix resources definition
* 2012-12-07 **V0.4.6** : bug fix in invite/publish/send tags (encode text as HTML in attributes)
* 2012-12-05 **V0.4.5** : bug fix in _FacebookSignedRequest_ appData property
* 2012-11-15 **V0.4.4** : for photo/video publishing, _FacebookGraphClient_ _publish_ method accepts now _InputStream_ argument type (instead of _FileInputStream_ only)
View
2 src/docs/guide/configuration.gdoc
@@ -14,7 +14,7 @@ grails.project.dependency.resolution = {
}
plugins {
//here go your plugin dependencies
- runtime ':facebook-sdk:0.4.7'
+ runtime ':facebook-sdk:0.4.8'
}
}
{code}
View
2 src/docs/guide/introduction.gdoc
@@ -21,6 +21,8 @@ WARNING: Since V0.4.0, @FacebookApp@, @FacebookSdkFilters@ and @FacebookAppServi
Please check [@FacebookContext@|guide:facebookContext] doc for more info.
{warning}
+* 2013-01-03 *V0.4.8* : bug fix token expiration time handling (in Facebook Page tabs)
+* 2012-12-20 *V0.4.7* : bug fix resources definition
* 2012-12-07 *V0.4.6* : bug fix in invite/publish/send tags (encode text as HTML in attributes)
* 2012-12-05 *V0.4.5* : bug fix in @FacebookSignedRequest@ appData property
* 2012-11-15 *V0.4.4* : for photo/video publishing, @FacebookGraphClient@ @publish@ method accepts now @InputStream@ argument type (instead of @FileInputStream@ only)
View
7 src/groovy/grails/plugin/facebooksdk/FacebookContext.groovy
@@ -72,8 +72,9 @@ class FacebookContext implements InitializingBean {
if (signedRequest.user.age) user.age = signedRequest.user.age
if (signedRequest.user.country) user.country = signedRequest.user.country
if (signedRequest.user.locale) user.locale = new Locale(signedRequest.user.locale.tokenize('_')[0], signedRequest.user.locale.tokenize('_')[1])
- // Load token in session scope
+ // Load token and expiration time in session scope
user.token
+ user.tokenExpirationTime
}
if (signedRequest.page) {
page = new FacebookContextPage(
@@ -89,6 +90,10 @@ class FacebookContext implements InitializingBean {
signedRequest = new FacebookSignedRequest(app.secret, cookie.value, FacebookSignedRequest.TYPE_COOKIE)
log.debug "Got signed request from cookie"
}
+ // Exchange token if it expires soon
+ if (authenticated && user.tokenLoaded && user.tokenExpiredSoon) {
+ user.exchangeToken()
+ }
}
boolean isAuthenticated() {
View
28 src/groovy/grails/plugin/facebooksdk/FacebookContextUser.groovy
@@ -2,7 +2,6 @@ package grails.plugin.facebooksdk
import com.restfb.exception.FacebookOAuthException
import org.apache.log4j.Logger
-import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
class FacebookContextUser {
@@ -16,6 +15,7 @@ class FacebookContextUser {
private long _id = -1
private String _token = null
+ private long _tokenExpirationTime = -1 // Unix time stamp in milliseconds
private Logger log = Logger.getLogger(getClass())
/*
@@ -91,7 +91,7 @@ class FacebookContextUser {
*/
String getToken() {
if (_token == null) {
- if (context.signedRequest.accessToken || context.signedRequest.code) { // First, consider a signed request if it's supplied. if there is a signed request, then it alone determines the access token.
+ if (context.signedRequest.accessToken || context.signedRequest.code) { // First, consider a signed request if it's supplied. If there is a signed request, then it alone determines the access token.
if (context.signedRequest.accessToken) {
// apps.facebook.com hands the access_token in the signed_request
_token = context.signedRequest.accessToken
@@ -144,8 +144,24 @@ class FacebookContextUser {
return _token
}
+ /*
+ * @description Get the token expiration time of the connected user.
+ */
long getTokenExpirationTime() {
- context.session.getData('expirationTime', 0).toLong()
+ if (_tokenExpirationTime == -1) {
+ // If a signed request is supplied, then it solely determines expiration time.
+ if (context.signedRequest.expirationTime) {
+ _tokenExpirationTime = context.signedRequest.expirationTime * 1000
+ log.debug "Got expiration time from signed request (expirationTime=$_tokenExpirationTime)"
+ if (context.session.getData('expirationTime') != _tokenExpirationTime) {
+ context.session.setData('expirationTime', _tokenExpirationTime)
+ }
+ } else {
+ _tokenExpirationTime = context.session.getData('expirationTime', 0).toLong()
+ log.debug "Got expiration from session (expirationTime=$_tokenExpirationTime)"
+ }
+ }
+ return _tokenExpirationTime
}
/*
@@ -171,6 +187,10 @@ class FacebookContextUser {
return expirationTime && (!isTokenExpired() && (expirationTime - new Date().time) < EXPIRATION_PREVENTION_THRESHOLD)
}
+ boolean isTokenLoaded() {
+ _token != null
+ }
+
String toString() {
"FacebookUser(id: $id)"
}
@@ -200,7 +220,7 @@ class FacebookContextUser {
context.session.setData('token', accessToken)
context.session.setData('code', code)
if (result['expires']) {
- Integer expires = result['expires'] as Integer
+ Integer expires = result['expires'].toInteger()
long expirationTime = new Date().time + expires * 1000
context.session.setData('expirationTime', expirationTime)
}

0 comments on commit a915944

Please sign in to comment.