Skip to content

Commit baf8d12

Browse files
committed
fix: Finish porting oauth2 usage in other parts of the codebase
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 867f3f8 commit baf8d12

3 files changed

Lines changed: 24 additions & 23 deletions

File tree

core/Controller/ClientFlowLoginController.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function showAuthPickerPage(string $clientIdentifier = '', string $user =
104104
$client = null;
105105
if ($clientIdentifier !== '') {
106106
$client = $this->clientMapper->getByIdentifier($clientIdentifier);
107-
$clientName = $client->getName();
107+
$clientName = $client->name;
108108
}
109109

110110
// No valid clientIdentifier given and no valid API Request (APIRequest header not set)
@@ -134,7 +134,7 @@ public function showAuthPickerPage(string $clientIdentifier = '', string $user =
134134

135135
$csp = new ContentSecurityPolicy();
136136
if ($client) {
137-
$csp->addAllowedFormActionDomain($client->getRedirectUri());
137+
$csp->addAllowedFormActionDomain($client->redirectUri);
138138
} else {
139139
$csp->addAllowedFormActionDomain('nc://*');
140140
}
@@ -191,12 +191,12 @@ public function grantPage(
191191
$client = null;
192192
if ($clientIdentifier !== '') {
193193
$client = $this->clientMapper->getByIdentifier($clientIdentifier);
194-
$clientName = $client->getName();
194+
$clientName = $client->name;
195195
}
196196

197197
$csp = new ContentSecurityPolicy();
198198
if ($client) {
199-
$csp->addAllowedFormActionDomain($client->getRedirectUri());
199+
$csp->addAllowedFormActionDomain($client->redirectUri);
200200
} else {
201201
$csp->addAllowedFormActionDomain('nc://*');
202202
}
@@ -274,7 +274,7 @@ public function generateAppPassword(
274274
$client = false;
275275
if ($clientIdentifier !== '') {
276276
$client = $this->clientMapper->getByIdentifier($clientIdentifier);
277-
$clientName = $client->getName();
277+
$clientName = $client->name;
278278
}
279279

280280
$token = $this->random->generate(72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
@@ -292,16 +292,16 @@ public function generateAppPassword(
292292
if ($client) {
293293
$code = $this->random->generate(128, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
294294
$accessToken = new AccessToken();
295-
$accessToken->setClientId($client->getId());
296-
$accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));
297-
$accessToken->setHashedCode(hash('sha512', $code));
298-
$accessToken->setTokenId($generatedToken->getId());
299-
$accessToken->setCodeCreatedAt($this->timeFactory->now()->getTimestamp());
295+
$accessToken->clientId = $client->id;
296+
$accessToken->encryptedToken = $this->crypto->encrypt($token, $code);
297+
$accessToken->hashedCode = hash('sha512', $code);
298+
$accessToken->tokenId = $generatedToken->getId();
299+
$accessToken->codeCreatedAt = $this->timeFactory->now()->getTimestamp();
300300
$this->accessTokenMapper->insert($accessToken);
301301

302302
$enableOcClients = $this->config->getSystemValueBool('oauth2.enable_oc_clients', false);
303303

304-
$redirectUri = $client->getRedirectUri();
304+
$redirectUri = $client->redirectUri;
305305
if ($enableOcClients && $redirectUri === 'http://localhost:*') {
306306
// Sanity check untrusted redirect URI provided by the client first
307307
if (!preg_match('/^http:\/\/localhost:[0-9]+$/', $providedRedirectUri)) {

lib/private/Repair/Owncloud/MigrateOauthTables.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ public function run(IOutput $output): void {
221221
$now = $this->timeFactory->now()->getTimestamp();
222222
$index = 0;
223223
while ($row = $result->fetchAssociative()) {
224-
$clientId = $row['client_id'];
225-
$refreshToken = $row['token'];
224+
$clientId = (int)$row['client_id'];
225+
$refreshToken = (string)$row['token'];
226226

227227
// Insert expired token so that it can be rotated on the next refresh
228228
$accessToken = $this->random->generate(72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
@@ -239,12 +239,12 @@ public function run(IOutput $output): void {
239239
$this->tokenProvider->updateToken($authToken);
240240

241241
$accessTokenEntity = new AccessToken();
242-
$accessTokenEntity->setTokenId($authToken->getId());
243-
$accessTokenEntity->setClientId($clientId);
244-
$accessTokenEntity->setHashedCode(hash('sha512', $refreshToken));
245-
$accessTokenEntity->setEncryptedToken($this->crypto->encrypt($accessToken, $refreshToken));
246-
$accessTokenEntity->setCodeCreatedAt($now);
247-
$accessTokenEntity->setTokenCount(1);
242+
$accessTokenEntity->tokenId = $authToken->getId();
243+
$accessTokenEntity->clientId = $clientId;
244+
$accessTokenEntity->hashedCode = hash('sha512', $refreshToken);
245+
$accessTokenEntity->encryptedToken = $this->crypto->encrypt($accessToken, $refreshToken);
246+
$accessTokenEntity->codeCreatedAt = $now;
247+
$accessTokenEntity->tokenCount = 1;
248248
$this->accessTokenMapper->insert($accessTokenEntity);
249249

250250
$index++;

tests/Core/Controller/ClientFlowLoginControllerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ public function testShowAuthPickerPageWithOauth(): void {
202202
['OCS-APIREQUEST', 'false'],
203203
]);
204204
$client = new Client();
205-
$client->setName('My external service');
206-
$client->setRedirectUri('https://example.com/redirect.php');
205+
$client->name = 'My external service';
206+
$client->redirectUri = 'https://example.com/redirect.php';
207207
$this->clientMapper
208208
->expects($this->once())
209209
->method('getByIdentifier')
@@ -491,8 +491,9 @@ public function testGeneratePasswordWithPasswordForOauthClient($redirectUri, $re
491491
)
492492
->willReturn($token);
493493
$client = new Client();
494-
$client->setName('My OAuth client');
495-
$client->setRedirectUri($redirectUri);
494+
$client->id = 42;
495+
$client->name = 'My OAuth client';
496+
$client->redirectUri = $redirectUri;
496497
$this->clientMapper
497498
->expects($this->once())
498499
->method('getByIdentifier')

0 commit comments

Comments
 (0)