|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 5 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 6 | + */ |
| 7 | + |
| 8 | +declare(strict_types=1); |
| 9 | + |
| 10 | +namespace OCA\UserOIDC\Event; |
| 11 | + |
| 12 | +use OCA\UserOIDC\Db\Provider; |
| 13 | +use OCP\EventDispatcher\Event; |
| 14 | + |
| 15 | +/** |
| 16 | + * This event is emitted with the raw token information when the login token is obtained |
| 17 | + * on a successful login and when it is refreshed |
| 18 | + * |
| 19 | + * It may be used by other apps to make use of the login token and stay informed when it gets refreshed |
| 20 | + * |
| 21 | + * The tokens are arrays with this shape: |
| 22 | + * [ |
| 23 | + * 'id_token' => '...', |
| 24 | + * 'access_token' => '...', |
| 25 | + * 'refresh_token' => '...', |
| 26 | + * 'expires_in' => 3600, |
| 27 | + * 'refresh_expires_in' => 3600, |
| 28 | + * 'created_at' => 123456789, |
| 29 | + * ] |
| 30 | + */ |
| 31 | +class UserObtainedTokenEvent extends Event { |
| 32 | + |
| 33 | + public function __construct( |
| 34 | + private string $userId, |
| 35 | + private ?array $oldToken, |
| 36 | + private array $newToken, |
| 37 | + private Provider $provider, |
| 38 | + private array $discovery, |
| 39 | + ) { |
| 40 | + parent::__construct(); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @return string The user ID of the user who obtained the token |
| 45 | + */ |
| 46 | + public function getUserId(): string { |
| 47 | + return $this->userId; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * This old token is set only when the token is refreshed |
| 52 | + * @return array|null The old token that has been refreshed |
| 53 | + */ |
| 54 | + public function getOldToken(): ?array { |
| 55 | + return $this->oldToken; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @return array The freshly obtained token |
| 60 | + */ |
| 61 | + public function getNewToken(): array { |
| 62 | + return $this->newToken; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @return Provider The related Oidc provider |
| 67 | + */ |
| 68 | + public function getProvider(): Provider { |
| 69 | + return $this->provider; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * The decoded discovery data from the discovery endpoint payload |
| 74 | + * @return array The discovery data |
| 75 | + */ |
| 76 | + public function getDiscovery(): array { |
| 77 | + return $this->discovery; |
| 78 | + } |
| 79 | +} |
0 commit comments