Permalink
Browse files

[php-sdk] Add Expired Error Handling

PHP-SDK doesn't update expired Cookie and doesn't handle expired error. PHP-SDK's getAccessToken method gets AccessToken from Cookie, if you set "Fb.init({cookie:true})" on web page with Javascript SDK.

Cherry-picked from Kobayo/php-sdk@04fe94a
  • Loading branch information...
1 parent 569d136 commit 88f3ff2eaa83def0183de5d29e038c72c56c4a12 @garbear committed Dec 25, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 Facebook/facebook-php-sdk/base_facebook.php
@@ -707,6 +707,12 @@ protected function getAccessTokenFromCode($code, $redirect_uri = null) {
return false;
}
+ // error check
+ $json_access_token = json_decode($access_token_response, true);
+ if ($json_access_token['error']['type'] == 'OAuthException') {
+ $this->throwAPIException($json_access_token);
+ }
+
if (empty($access_token_response)) {
return false;
}
@@ -1084,6 +1090,15 @@ protected function throwAPIException($result) {
$this->setAccessToken(null);
$this->user = 0;
$this->clearAllPersistentData();
+ } else if ((strpos($message, 'Code was invalid or expired') !== false)) {
+ // session clear
+ $this->destroySession();
+
+ // cookie crear
+ setcookie($this->getSignedRequestCookieName(), '', time() - 3600);
+
+ // FIXME: need to delete on real time ?
+ // unset($_COOKIE[$this->getSignedRequestCookieName()]);
}
}

0 comments on commit 88f3ff2

Please sign in to comment.