okapi r887: fixed oauth nonces handling

This commit is contained in:
following
2013-08-28 13:37:03 +02:00
parent cbcc20876d
commit 6847609902
2 changed files with 19 additions and 24 deletions

View File

@@ -47,30 +47,25 @@ class OkapiDataStore extends OAuthDataStore
public function lookup_nonce($consumer, $token, $nonce, $timestamp)
{
# First, see if it exists. Note, that old nonces are periodically deleted.
$exists = Db::select_value("
select 1
from okapi_nonces
where
consumer_key = '".mysql_real_escape_string($consumer->key)."'
and `key` = '".mysql_real_escape_string($nonce)."'
and timestamp = '".mysql_real_escape_string($timestamp)."'
");
if ($exists)
try
{
Db::execute("
insert into okapi_nonces (consumer_key, `key`, timestamp)
values (
'".mysql_real_escape_string($consumer->key)."',
'".mysql_real_escape_string($nonce)."',
'".mysql_real_escape_string($timestamp)."'
);
");
return null;
}
catch (\Exception $e)
{
# INSERT failed. Assume this nonce was already used.
# Note, that old nonces are periodically deleted (see cronjobs).
return $nonce;
# It didn't exist. We have to remember it.
Db::execute("
insert into okapi_nonces (consumer_key, `key`, timestamp)
values (
'".mysql_real_escape_string($consumer->key)."',
'".mysql_real_escape_string($nonce)."',
'".mysql_real_escape_string($timestamp)."'
);
");
return null;
}
}
public function new_request_token($consumer, $callback = null)