namespace OCA\Grauphel\Lib;
/**
- * Token store
+ * OAuth token store
*
* @category Tools
* @package Grauphel
*/
class TokenStorage
{
+ /**
+ * @var \OCP\IDBConnection
+ */
+ protected $db;
+
+ public function __construct()
+ {
+ $this->db = \OC::$server->getDatabaseConnection();
+ }
+
/**
* Delete token
*
*/
public function delete($type, $tokenKey)
{
- \OC_DB::executeAudited(
+ $this->db->executeQuery(
'DELETE FROM `*PREFIX*grauphel_oauth_tokens`'
. ' WHERE `token_key` = ? AND `token_type` = ?',
array($tokenKey, $type)
*/
public function store(Token $token)
{
- \OC_DB::executeAudited(
+ $this->db->executeQuery(
'INSERT INTO `*PREFIX*grauphel_oauth_tokens`'
. '(`token_user`, `token_type`, `token_key`, `token_secret`, `token_verifier`, `token_callback`, `token_client`, `token_lastuse`)'
. ' VALUES(?, ?, ?, ?, ?, ?, ?, ?)',
*/
public function load($type, $tokenKey)
{
- $tokenRow = \OC_DB::executeAudited(
+ $tokenRow = $this->db->executeQuery(
'SELECT * FROM `*PREFIX*grauphel_oauth_tokens`'
. ' WHERE `token_key` = ? AND `token_type` = ?',
array($tokenKey, $type)
- )->fetchRow();
+ )->fetch();
if ($tokenRow === false) {
throw new OAuthException(
*/
public function loadForUser($username, $type)
{
- $result = \OC_DB::executeAudited(
+ $result = $this->db->executeQuery(
'SELECT * FROM `*PREFIX*grauphel_oauth_tokens`'
. ' WHERE `token_user` = ? AND `token_type` = ?',
array($username, $type)
);
$tokens = array();
- while ($tokenRow = $result->fetchRow()) {
+ while ($tokenRow = $result->fetch()) {
$tokens[] = $this->fromDb($tokenRow);
}
*/
public function updateLastUse($tokenKey)
{
- \OC_DB::executeAudited(
+ $this->db->executeQuery(
'UPDATE `*PREFIX*grauphel_oauth_tokens`'
. ' SET `token_lastuse` = ? WHERE `token_key` = ?',
array(