/**
* Validate any core, required properties have been set.
+ *
* @throws InvalidArgumentException
*/
protected function validateInitial()
}
if (strpos($this->issuer, 'https://') !== 0) {
- throw new InvalidArgumentException("Issuer value must start with https://");
+ throw new InvalidArgumentException('Issuer value must start with https://');
}
}
/**
* Perform a full validation on these settings.
+ *
* @throws InvalidArgumentException
*/
public function validate(): void
/**
* Discover and autoload settings from the configured issuer.
+ *
* @throws OidcIssuerDiscoveryException
*/
public function discoverFromIssuer(ClientInterface $httpClient, Repository $cache, int $cacheMinutes)
{
try {
$cacheKey = 'oidc-discovery::' . $this->issuer;
- $discoveredSettings = $cache->remember($cacheKey, $cacheMinutes * 60, function() use ($httpClient) {
+ $discoveredSettings = $cache->remember($cacheKey, $cacheMinutes * 60, function () use ($httpClient) {
return $this->loadSettingsFromIssuerDiscovery($httpClient);
});
$this->applySettingsFromArray($discoveredSettings);
}
if ($result['issuer'] !== $this->issuer) {
- throw new OidcIssuerDiscoveryException("Unexpected issuer value found on discovery response");
+ throw new OidcIssuerDiscoveryException('Unexpected issuer value found on discovery response');
}
$discoveredSettings = [];
if (!empty($result['jwks_uri'])) {
$keys = $this->loadKeysFromUri($result['jwks_uri'], $httpClient);
- $discoveredSettings['keys'] = array_filter($keys);
+ $discoveredSettings['keys'] = $this->filterKeys($keys);
}
return $discoveredSettings;
*/
protected function filterKeys(array $keys): array
{
- return array_filter($keys, function(array $key) {
- return $key['key'] === 'RSA' && $key['use'] === 'sig' && $key['alg'] === 'RS256';
+ return array_filter($keys, function (array $key) {
+ $alg = $key['alg'] ?? null;
+
+ return $key['kty'] === 'RSA' && $key['use'] === 'sig' && (is_null($alg) || $alg === 'RS256');
});
}
/**
* Return an array of jwks as PHP key=>value arrays.
+ *
* @throws ClientExceptionInterface
* @throws OidcIssuerDiscoveryException
*/
$result = json_decode($response->getBody()->getContents(), true);
if (empty($result) || !is_array($result) || !isset($result['keys'])) {
- throw new OidcIssuerDiscoveryException("Error reading keys from issuer jwks_uri");
+ throw new OidcIssuerDiscoveryException('Error reading keys from issuer jwks_uri');
}
return $result['keys'];
foreach ($settingKeys as $setting) {
$settings[$setting] = $this->$setting;
}
+
return $settings;
}
-}
\ No newline at end of file
+}