summaryrefslogtreecommitdiffstats
path: root/apps/oauth2/lib/Db
diff options
context:
space:
mode:
Diffstat (limited to 'apps/oauth2/lib/Db')
-rw-r--r--apps/oauth2/lib/Db/AccessTokenMapper.php14
-rw-r--r--apps/oauth2/lib/Db/ClientMapper.php22
2 files changed, 36 insertions, 0 deletions
diff --git a/apps/oauth2/lib/Db/AccessTokenMapper.php b/apps/oauth2/lib/Db/AccessTokenMapper.php
index 2751302522c..51b97bf8d7a 100644
--- a/apps/oauth2/lib/Db/AccessTokenMapper.php
+++ b/apps/oauth2/lib/Db/AccessTokenMapper.php
@@ -22,6 +22,7 @@
namespace OCA\OAuth2\Db;
use OCP\AppFramework\Db\Mapper;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
class AccessTokenMapper extends Mapper {
@@ -48,4 +49,17 @@ class AccessTokenMapper extends Mapper {
$result->closeCursor();
return AccessToken::fromRow($row);
}
+
+ /**
+ * delete all access token from a given client
+ *
+ * @param int $id
+ */
+ public function deleteByClientId($id) {
+ $qb = $this->db->getQueryBuilder();
+ $qb
+ ->delete($this->tableName)
+ ->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
+ $qb->execute();
+ }
}
diff --git a/apps/oauth2/lib/Db/ClientMapper.php b/apps/oauth2/lib/Db/ClientMapper.php
index 38751a2e5cf..cf00afacb70 100644
--- a/apps/oauth2/lib/Db/ClientMapper.php
+++ b/apps/oauth2/lib/Db/ClientMapper.php
@@ -22,6 +22,7 @@
namespace OCA\OAuth2\Db;
use OCP\AppFramework\Db\Mapper;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
class ClientMapper extends Mapper {
@@ -55,6 +56,27 @@ class ClientMapper extends Mapper {
}
/**
+ * @param string $uid internal uid of the client
+ * @return Client
+ */
+ public function getByUid($uid) {
+ $qb = $this->db->getQueryBuilder();
+ $qb
+ ->select('*')
+ ->from($this->tableName)
+ ->where($qb->expr()->eq('id', $qb->createNamedParameter($uid, IQueryBuilder::PARAM_INT)));
+ $result = $qb->execute();
+ $row = $result->fetch();
+ $result->closeCursor();
+
+ if (!is_array($row)) {
+ $row = [];
+ }
+
+ return Client::fromRow($row);
+ }
+
+ /**
* @return Client[]
*/
public function getClients() {