aboutsummaryrefslogtreecommitdiff
path: root/lib/tokenstorage.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2014-09-30 23:13:49 +0200
committerChristian Weiske <cweiske@cweiske.de>2014-09-30 23:13:49 +0200
commiteb5c81dea5a60bc65d3ec607daf5ad81fd709928 (patch)
tree81407f1e67adba222a020e142d0ebfb15a3f5ef3 /lib/tokenstorage.php
parentf38e545235173bb145e4b1c9c29dc2960a0a3389 (diff)
downloadgrauphel-eb5c81dea5a60bc65d3ec607daf5ad81fd709928.tar.gz
grauphel-eb5c81dea5a60bc65d3ec607daf5ad81fd709928.zip
store client name and last use time for tokens. show them in token management
Diffstat (limited to 'lib/tokenstorage.php')
-rw-r--r--lib/tokenstorage.php29
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/tokenstorage.php b/lib/tokenstorage.php
index b9689ab..cdbce11 100644
--- a/lib/tokenstorage.php
+++ b/lib/tokenstorage.php
@@ -37,15 +37,17 @@ class TokenStorage
{
\OC_DB::executeAudited(
'INSERT INTO `*PREFIX*grauphel_oauth_tokens`'
- . '(`token_user`, `token_type`, `token_key`, `token_secret`, `token_verifier`, `token_callback`)'
- . ' VALUES(?, ?, ?, ?, ?, ?)',
+ . '(`token_user`, `token_type`, `token_key`, `token_secret`, `token_verifier`, `token_callback`, `token_client`, `token_lastuse`)'
+ . ' VALUES(?, ?, ?, ?, ?, ?, ?, ?)',
array(
$token->user,
$token->type,
$token->tokenKey,
(string) $token->secret,
(string) $token->verifier,
- (string) $token->callback
+ (string) $token->callback,
+ (string) $token->client,
+ (string) date('c'),
)
);
}
@@ -133,6 +135,25 @@ class TokenStorage
return $tokens;
}
+ /**
+ * Update the "last use" field of a token
+ *
+ * @param string $tokenKey Random token string to load
+ *
+ * @return void
+ */
+ public function updateLastUse($tokenKey)
+ {
+ \OC_DB::executeAudited(
+ 'UPDATE `*PREFIX*grauphel_oauth_tokens`'
+ . ' SET `token_lastuse` = ? WHERE `token_key` = ?',
+ array(
+ (string) date('c'),
+ $tokenKey,
+ )
+ );
+ }
+
protected function fromDb($tokenRow)
{
$token = new Token();
@@ -142,6 +163,8 @@ class TokenStorage
$token->user = $tokenRow['token_user'];
$token->verifier = $tokenRow['token_verifier'];
$token->callback = $tokenRow['token_callback'];
+ $token->client = $tokenRow['token_client'];
+ $token->lastuse = \strtotime($tokenRow['token_lastuse']);
return $token;
}
}