ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\WOPI\Discovery\ProofKeyRefresh Class Reference

Fetches the proof keys from the discovery again when a request could not be verified with the stored ones - the WOPI client may have rotated its keys since the last crawl, see https://learn.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/online/scenarios/proofkeys. More...

+ Collaboration diagram for ILIAS\WOPI\Discovery\ProofKeyRefresh:

Public Member Functions

 __construct (private ProofKeyRepository $repository, private \ilSetting $settings, private \Closure $fetch, ?\Closure $clock=null)
 
 __invoke ()
 

Data Fields

const MIN_INTERVAL = 5 * 60
 

Private Attributes

const LAST_REFRESH = 'wopi_proof_refreshed_at'
 
Closure $clock
 

Detailed Description

Fetches the proof keys from the discovery again when a request could not be verified with the stored ones - the WOPI client may have rotated its keys since the last crawl, see https://learn.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/online/scenarios/proofkeys.

Every request failing the verification would trigger a fetch, so it happens at most once within MIN_INTERVAL. A failed fetch keeps the stored keys.

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 33 of file ProofKeyRefresh.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\WOPI\Discovery\ProofKeyRefresh::__construct ( private ProofKeyRepository  $repository,
private \ilSetting  $settings,
private \Closure  $fetch,
?\Closure  $clock = null 
)
Parameters

Closure(): ?ProofKeys $fetch reads the proof keys from the discovery

Parameters

Closure(): int|null $clock returns the current unix timestamp, for testing

Definition at line 47 of file ProofKeyRefresh.php.

52 {
53 $this->clock = $clock ?? static fn(): int => time();
54 }

References ILIAS\WOPI\Discovery\ProofKeyRefresh\$clock.

Member Function Documentation

◆ __invoke()

ILIAS\WOPI\Discovery\ProofKeyRefresh::__invoke ( )
Returns
ProofKeys|null the keys just fetched, null if nothing was fetched

Definition at line 59 of file ProofKeyRefresh.php.

59 : ?ProofKeys
60 {
61 $now = ($this->clock)();
62 if ($now - (int) $this->settings->get(self::LAST_REFRESH, '0') < self::MIN_INTERVAL) {
63 return null;
64 }
65 $this->settings->set(self::LAST_REFRESH, (string) $now);
66
67 try {
68 $keys = ($this->fetch)();
69 } catch (\Throwable) {
70 return null;
71 }
72 if ($keys === null) {
73 return null;
74 }
75 $this->repository->store($keys);
76
77 return $keys;
78 }

References ILIAS\WOPI\Discovery\ProofKeyRefresh\$clock, ILIAS\WOPI\Discovery\ProofKeyRefresh\MIN_INTERVAL, ILIAS\UI\examples\Deck\repository(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Field Documentation

◆ $clock

Closure ILIAS\WOPI\Discovery\ProofKeyRefresh::$clock
private

◆ LAST_REFRESH

const ILIAS\WOPI\Discovery\ProofKeyRefresh::LAST_REFRESH = 'wopi_proof_refreshed_at'
private

Definition at line 36 of file ProofKeyRefresh.php.

◆ MIN_INTERVAL

const ILIAS\WOPI\Discovery\ProofKeyRefresh::MIN_INTERVAL = 5 * 60

The documentation for this class was generated from the following file: