Fix bug #8: Titled blank notes cause SQL error
[grauphel.git] / lib / oauth.php
index d6c72e835daf2123cc6f95156b2e1d7a662f986c..231a177cfc2cd177cd3afeddda624d758b6758e2 100644 (file)
@@ -98,7 +98,25 @@ class OAuth
 
     public function accessTokenHandler(\OAuthProvider $provider)
     {
-        $token = $this->tokens->load('access', $provider->token);
+        if ($provider->token == '') {
+            //conboy sends empty token when not authed yet
+            return OAUTH_PARAMETER_ABSENT;
+        }
+
+        try {
+            $token = $this->tokens->load('access', $provider->token);
+        } catch (OAuthException $e) {
+            if ($e->getCode() == OAUTH_TOKEN_REJECTED) {
+                return OAUTH_TOKEN_REJECTED;
+            }
+            throw $e;
+        }
+
+        if (time() - $token->lastuse > 60) {
+            //time to update lastuse after at least a minute
+            $this->tokens->updateLastUse($token->tokenKey);
+        }
+
         $provider->token_secret = $token->secret;
         return OAUTH_OK;
     }
@@ -135,7 +153,7 @@ class OAuth
     /**
      * Get a new oauth provider instance.
      * Used to work around the fastcgi bug in oauthprovider.
-     * 
+     *
      * @return \OAuthProvider
      */
     public static function getProvider()