Send HTTP 401 on invalid token
authorChristian Weiske <cweiske@cweiske.de>
Fri, 26 Sep 2014 12:32:03 +0000 (14:32 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 26 Sep 2014 12:32:03 +0000 (14:32 +0200)
lib/oauth.php
lib/tokenstorage.php

index 6900c20305e0fba6ca68d8bd79886c91d0b6cfc6..5f84e7e319c62b87be689239cda8e5f51088a814 100644 (file)
@@ -103,7 +103,14 @@ class OAuth
             return OAUTH_PARAMETER_ABSENT;
         }
 
             return OAUTH_PARAMETER_ABSENT;
         }
 
-        $token = $this->tokens->load('access', $provider->token);
+        try {
+            $token = $this->tokens->load('access', $provider->token);
+        } catch (OAuthException $e) {
+            if ($e->getCode() == OAUTH_TOKEN_REJECTED) {
+                return OAUTH_TOKEN_REJECTED;
+            }
+            throw $e;
+        }
         $provider->token_secret = $token->secret;
         return OAUTH_OK;
     }
         $provider->token_secret = $token->secret;
         return OAUTH_OK;
     }
index f8f0806f95b89d61f9f092c483852af42fb674ce..4b5f42094978a139c156a41aff6b8f3e1c47d5ac 100644 (file)
@@ -95,12 +95,15 @@ class TokenStorage
         )->fetchRow();
 
         if ($tokenRow === false) {
         )->fetchRow();
 
         if ($tokenRow === false) {
-            throw new OAuthException('Unknown token: ' . $type . ' / ' . $tokenKey);
+            throw new OAuthException(
+                'Unknown token: ' . $type . ' / ' . $tokenKey,
+                OAUTH_TOKEN_REJECTED
+            );
         }
 
         $token = $this->fromDb($tokenRow);
         if ($token->tokenKey != $tokenKey) {
         }
 
         $token = $this->fromDb($tokenRow);
         if ($token->tokenKey != $tokenKey) {
-            throw new OAuthException('Invalid token');
+            throw new OAuthException('Invalid token', OAUTH_TOKEN_REJECTED);
         }
 
         return $token;
         }
 
         return $token;