]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/apioauthstore.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / lib / apioauthstore.php
index 32110d057572923ff183868a6b89cb057815f65b..eca93866f002bc982c53aea354d88f2847ebd917 100644 (file)
@@ -23,7 +23,6 @@ require_once INSTALLDIR . '/lib/oauthstore.php';
 
 class ApiStatusNetOAuthDataStore extends StatusNetOAuthDataStore
 {
-
     function lookup_consumer($consumer_key)
     {
         $con = Consumer::staticGet('consumer_key', $consumer_key);
@@ -39,7 +38,6 @@ class ApiStatusNetOAuthDataStore extends StatusNetOAuthDataStore
     function getAppByRequestToken($token_key)
     {
         // Look up the full req tokenx
-
         $req_token = $this->lookup_token(null,
                                          'request',
                                          $token_key);
@@ -50,7 +48,6 @@ class ApiStatusNetOAuthDataStore extends StatusNetOAuthDataStore
         }
 
         // Look up the full Token
-
         $token = new Token();
         $token->tok = $req_token->key;
         $result = $token->find(true);
@@ -150,14 +147,40 @@ class ApiStatusNetOAuthDataStore extends StatusNetOAuthDataStore
                 }
 
                 // Okay, good
-
                 return new OAuthToken($at->tok, $at->secret);
             }
-
         } else {
             return null;
         }
     }
 
-}
+    /**
+     * Revoke specified access token
+     *
+     * Revokes the token specified by $token_key.
+     * Throws exceptions in case of error.
+     *
+     * @param string $token_key the token to be revoked
+     * @param int    $type      type of token (0 = req, 1 = access)
+     *
+     * @access public
+     *
+     * @return void
+     */
+    public function revoke_token($token_key, $type = 0) {
+        $rt = new Token();
+        $rt->tok = $token_key;
+        $rt->type = $type;
+        $rt->state = 0;
+
+        if (!$rt->find(true)) {
+            // TRANS: Exception thrown when an attempt is made to revoke an unknown token.
+            throw new Exception(_('Tried to revoke unknown token.'));
+        }
 
+        if (!$rt->delete()) {
+            // TRANS: Exception thrown when an attempt is made to remove a revoked token.
+            throw new Exception(_('Failed to delete revoked token.'));
+        }
+    }
+}