Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions lib/Event/TokenRefreshedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

declare(strict_types=1);

namespace OCA\UserOIDC\Event;

use OCA\UserOIDC\Db\Provider;
use OCP\EventDispatcher\Event;

/**
* This event is emitted with the raw token information when the login token is refreshed
*
* It may be used for further handling of oidc authenticated requests
*/
class TokenRefreshedEvent extends Event {

public function __construct(
private array $oldToken,
private array $newToken,
private Provider $provider,
private array $discovery,
) {
parent::__construct();
}

public function getOldToken(): array {
return $this->oldToken;
}

public function getNewToken(): array {
return $this->newToken;
}

public function getProvider(): Provider {
return $this->provider;
}

public function getDiscovery(): array {
return $this->discovery;
}
}
8 changes: 8 additions & 0 deletions lib/Service/TokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OC\Authentication\Token\IProvider;
use OCA\UserOIDC\AppInfo\Application;
use OCA\UserOIDC\Db\ProviderMapper;
use OCA\UserOIDC\Event\TokenRefreshedEvent;
use OCA\UserOIDC\Exception\TokenExchangeFailedException;
use OCA\UserOIDC\Helper\HttpClientHelper;
use OCA\UserOIDC\Model\Token;
Expand Down Expand Up @@ -276,6 +277,13 @@ public function refresh(Token $token): Token {

$bodyArray = json_decode(trim($body), true, 512, JSON_THROW_ON_ERROR);
$this->logger->debug('[TokenService] ---- Refresh token success');

$this->eventDispatcher->dispatchTyped(
new TokenRefreshedEvent(
$token->jsonSerialize(), $bodyArray, $oidcProvider, $discovery
)
);

return $this->storeToken(
array_merge($bodyArray, ['provider_id' => $token->getProviderId()])
);
Expand Down
Loading