]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1046126: Do not generate a new API token every time you access a bug-related...
authorDavid Lawrence <dkl@mozilla.com>
Mon, 8 Sep 2014 13:43:00 +0000 (13:43 +0000)
committerDavid Lawrence <dkl@mozilla.com>
Mon, 8 Sep 2014 13:43:00 +0000 (13:43 +0000)
r=sgreen,a=glob

Bugzilla/Token.pm

index 670f5a661a0fdf034114a8a1e850bcdcd5421627..24ffad3c34a88bde966781379914f4b4aaec174c 100644 (file)
@@ -34,9 +34,16 @@ use parent qw(Exporter);
 
 # Create a token used for internal API authentication
 sub issue_api_token {
-    # Generates a random token, adds it to the tokens table, and returns
-    # the token to the caller.
-    return _create_token(Bugzilla->user->id, 'api_token', '');
+    # Generates a random token, adds it to the tokens table if one does not
+    # already exist, and returns the token to the caller.
+    my $dbh  = Bugzilla->dbh;
+    my $user = Bugzilla->user;
+    my ($token) = $dbh->selectrow_array("
+        SELECT token FROM tokens
+         WHERE userid = ? AND tokentype = 'api_token'
+               AND (" . $dbh->sql_date_math('issuedate', '+', (MAX_TOKEN_AGE * 24 - 12), 'HOUR') . ") > NOW()",
+        undef, $user->id);
+    return $token // _create_token($user->id, 'api_token', '');
 }
 
 # Creates and sends a token to create a new user account.