diff --git a/apps/oauth2/lib/Db/AccessTokenMapper.php b/apps/oauth2/lib/Db/AccessTokenMapper.php index 408aefdda93..a5e407b3ed1 100644 --- a/apps/oauth2/lib/Db/AccessTokenMapper.php +++ b/apps/oauth2/lib/Db/AccessTokenMapper.php @@ -57,7 +57,7 @@ class AccessTokenMapper extends Repository { $now = $timeFactory->now()->getTimestamp(); $maxTokenCreationTs = $now - OauthApiController::AUTHORIZATION_CODE_EXPIRES_AFTER; - $qb = $this->getDatabaseConnection()->getQueryBuilder(); + $qb = $this->connection->getQueryBuilder(); $qb ->delete($this->getTableName()) ->where($qb->expr()->eq('token_count', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))) @@ -72,7 +72,7 @@ class AccessTokenMapper extends Repository { * @return int Number of updated rows */ public function rotateToken(int $id, string $oldCode, string $newCode, string $encryptedToken, bool $expectAuthorizationCodeState): int { - $qb = $this->getDatabaseConnection()->getQueryBuilder(); + $qb = $this->connection->getQueryBuilder(); $qb ->update($this->getTableName()) ->set('hashed_code', $qb->createNamedParameter(hash('sha512', $newCode))) diff --git a/core/Controller/ClientFlowLoginController.php b/core/Controller/ClientFlowLoginController.php index 060091621bc..22c598c154b 100644 --- a/core/Controller/ClientFlowLoginController.php +++ b/core/Controller/ClientFlowLoginController.php @@ -104,7 +104,7 @@ class ClientFlowLoginController extends Controller { $client = null; if ($clientIdentifier !== '') { $client = $this->clientMapper->getByIdentifier($clientIdentifier); - $clientName = $client->getName(); + $clientName = $client->name; } // No valid clientIdentifier given and no valid API Request (APIRequest header not set) @@ -134,7 +134,7 @@ class ClientFlowLoginController extends Controller { $csp = new ContentSecurityPolicy(); if ($client) { - $csp->addAllowedFormActionDomain($client->getRedirectUri()); + $csp->addAllowedFormActionDomain($client->redirectUri); } else { $csp->addAllowedFormActionDomain('nc://*'); } @@ -191,12 +191,12 @@ class ClientFlowLoginController extends Controller { $client = null; if ($clientIdentifier !== '') { $client = $this->clientMapper->getByIdentifier($clientIdentifier); - $clientName = $client->getName(); + $clientName = $client->name; } $csp = new ContentSecurityPolicy(); if ($client) { - $csp->addAllowedFormActionDomain($client->getRedirectUri()); + $csp->addAllowedFormActionDomain($client->redirectUri); } else { $csp->addAllowedFormActionDomain('nc://*'); } @@ -274,7 +274,7 @@ class ClientFlowLoginController extends Controller { $client = false; if ($clientIdentifier !== '') { $client = $this->clientMapper->getByIdentifier($clientIdentifier); - $clientName = $client->getName(); + $clientName = $client->name; } $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); @@ -292,16 +292,16 @@ class ClientFlowLoginController extends Controller { if ($client) { $code = $this->random->generate(128, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); $accessToken = new AccessToken(); - $accessToken->setClientId($client->getId()); - $accessToken->setEncryptedToken($this->crypto->encrypt($token, $code)); - $accessToken->setHashedCode(hash('sha512', $code)); - $accessToken->setTokenId($generatedToken->getId()); - $accessToken->setCodeCreatedAt($this->timeFactory->now()->getTimestamp()); + $accessToken->clientId = $client->id; + $accessToken->encryptedToken = $this->crypto->encrypt($token, $code); + $accessToken->hashedCode = hash('sha512', $code); + $accessToken->tokenId = $generatedToken->getId(); + $accessToken->codeCreatedAt = $this->timeFactory->now()->getTimestamp(); $this->accessTokenMapper->insert($accessToken); $enableOcClients = $this->config->getSystemValueBool('oauth2.enable_oc_clients', false); - $redirectUri = $client->getRedirectUri(); + $redirectUri = $client->redirectUri; if ($enableOcClients && $redirectUri === 'http://localhost:*') { // Sanity check untrusted redirect URI provided by the client first if (!preg_match('/^http:\/\/localhost:[0-9]+$/', $providedRedirectUri)) { diff --git a/lib/private/Repair/Owncloud/MigrateOauthTables.php b/lib/private/Repair/Owncloud/MigrateOauthTables.php index 7c371792bbc..f4122af5175 100644 --- a/lib/private/Repair/Owncloud/MigrateOauthTables.php +++ b/lib/private/Repair/Owncloud/MigrateOauthTables.php @@ -221,8 +221,8 @@ class MigrateOauthTables implements IRepairStep { $now = $this->timeFactory->now()->getTimestamp(); $index = 0; while ($row = $result->fetchAssociative()) { - $clientId = $row['client_id']; - $refreshToken = $row['token']; + $clientId = (int)$row['client_id']; + $refreshToken = (string)$row['token']; // Insert expired token so that it can be rotated on the next refresh $accessToken = $this->random->generate(72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); @@ -239,12 +239,12 @@ class MigrateOauthTables implements IRepairStep { $this->tokenProvider->updateToken($authToken); $accessTokenEntity = new AccessToken(); - $accessTokenEntity->setTokenId($authToken->getId()); - $accessTokenEntity->setClientId($clientId); - $accessTokenEntity->setHashedCode(hash('sha512', $refreshToken)); - $accessTokenEntity->setEncryptedToken($this->crypto->encrypt($accessToken, $refreshToken)); - $accessTokenEntity->setCodeCreatedAt($now); - $accessTokenEntity->setTokenCount(1); + $accessTokenEntity->tokenId = $authToken->getId(); + $accessTokenEntity->clientId = $clientId; + $accessTokenEntity->hashedCode = hash('sha512', $refreshToken); + $accessTokenEntity->encryptedToken = $this->crypto->encrypt($accessToken, $refreshToken); + $accessTokenEntity->codeCreatedAt = $now; + $accessTokenEntity->tokenCount = 1; $this->accessTokenMapper->insert($accessTokenEntity); $index++; diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php index f77db8d79e7..77256250742 100644 --- a/tests/Core/Controller/ClientFlowLoginControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php @@ -202,8 +202,8 @@ class ClientFlowLoginControllerTest extends TestCase { ['OCS-APIREQUEST', 'false'], ]); $client = new Client(); - $client->setName('My external service'); - $client->setRedirectUri('https://example.com/redirect.php'); + $client->name = 'My external service'; + $client->redirectUri = 'https://example.com/redirect.php'; $this->clientMapper ->expects($this->once()) ->method('getByIdentifier') @@ -491,8 +491,9 @@ class ClientFlowLoginControllerTest extends TestCase { ) ->willReturn($token); $client = new Client(); - $client->setName('My OAuth client'); - $client->setRedirectUri($redirectUri); + $client->id = 42; + $client->name = 'My OAuth client'; + $client->redirectUri = $redirectUri; $this->clientMapper ->expects($this->once()) ->method('getByIdentifier')