Skip to content

Commit

Permalink
more defensive migration, moved end session manipulation into loginco…
Browse files Browse the repository at this point in the history
…ntroller, css class tweak

Signed-off-by: Florian Klinger <[email protected]>
  • Loading branch information
nc-fkl committed Dec 1, 2023
1 parent 1c8edf0 commit 48898d2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
8 changes: 7 additions & 1 deletion lib/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,13 @@ public function singleLogoutService() {
$message = $this->l10n->t('There is not such OpenID Connect provider.');
return $this->buildErrorTemplateResponse($message, Http::STATUS_NOT_FOUND, ['provider_id' => $providerId]);
}
$endSessionEndpoint = $this->discoveryService->obtainDiscovery($provider)['end_session_endpoint'];

// Check if a custom end_session_endpoint is deposited otherwise use the default one provided by the openid-configuration
$discoveryData = $this->discoveryService->obtainDiscovery($provider);
$defaultEndSessionEndpoint = $discoveryData['end_session_endpoint'];
$customEndSessionEndpoint = json_decode(json_encode($provider), true)['endSessionEndpoint'];
$endSessionEndpoint = $customEndSessionEndpoint ?? $defaultEndSessionEndpoint;

if ($endSessionEndpoint) {
$endSessionEndpoint .= '?post_logout_redirect_uri=' . $targetUrl;
$endSessionEndpoint .= '&client_id=' . $provider->getClientId();
Expand Down
1 change: 1 addition & 0 deletions lib/Db/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @method void setClientSecret(string $clientSecret)
* @method string getDiscoveryEndpoint()
* @method void setDiscoveryEndpoint(string $discoveryEndpoint)
* @method string getEndSessionEndpoint()
* @method void setEndSessionEndpoint(string $endSessionEndpoint)
* @method void setScope(string $scope)
*/
Expand Down
15 changes: 10 additions & 5 deletions lib/Migration/Version010304Date20231130104459.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use OCP\DB\Types;

/**
* Auto-generated migration step: Please modify to your needs!
Expand All @@ -45,11 +46,15 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable('user_oidc_providers');
$table->addColumn('end_session_endpoint', 'string', [
'notnull' => false,
'length' => 255,
]);
if ($schema->hasTable('user_oidc_providers')) {
$table = $schema->getTable('user_oidc_providers');
if (!$table->hasColumn('end_session_endpoint')) {
$table->addColumn('end_session_endpoint', Types::STRING, [
'notnull' => false,
'length' => 255,
]);
}
}

return $schema;
}
Expand Down
9 changes: 0 additions & 9 deletions lib/Service/DiscoveryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ public function obtainDiscovery(Provider $provider): array {
$response = $client->get($url);
$cachedDiscovery = $response->getBody();

// Manipulate the response with the custom endpoint url
$endpointData = json_encode($this->providerService->getProviderWithSettings($provider->getId()));
$endpointData = json_decode($endpointData)->endSessionEndpoint;
if ($endpointData) {
$discoveryData = json_decode($cachedDiscovery);
$discoveryData->end_session_endpoint = $endpointData;
$cachedDiscovery = json_encode($discoveryData);
}

$this->cache->set($cacheKey, $cachedDiscovery, self::INVALIDATE_DISCOVERY_CACHE_AFTER_SECONDS);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/SettingsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default {
min-width: 200px;
flex-grow: 1;
}
input[type=text].italic-placeholder::placeholder {
.italic-placeholder::placeholder {
font-style: italic;
}
}
Expand Down

0 comments on commit 48898d2

Please sign in to comment.