*/
protected function loadFromJwkArray(array $jwk)
{
- if ($jwk['alg'] !== 'RS256') {
- throw new OidcInvalidKeyException("Only RS256 keys are currently supported. Found key using {$jwk['alg']}");
+ // 'alg' is optional for a JWK, but we will still attempt to validate if
+ // it exists otherwise presume it will be compatible.
+ $alg = $jwk['alg'] ?? null;
+ if ($jwk['kty'] !== 'RSA' || !(is_null($alg) || $alg === 'RS256')) {
+ throw new OidcInvalidKeyException("Only RS256 keys are currently supported. Found key using {$alg}");
}
- if (empty($jwk['use'])) {
- throw new OidcInvalidKeyException('A "use" parameter on the provided key is expected');
- }
-
- if ($jwk['use'] !== 'sig') {
+ // 'use' is optional for a JWK but we assume 'sig' where no value exists since that's what
+ // the OIDC discovery spec infers since 'sig' MUST be set if encryption keys come into play.
+ $use = $jwk['use'] ?? 'sig';
+ if ($use !== 'sig') {
throw new OidcInvalidKeyException("Only signature keys are currently supported. Found key for use {$jwk['use']}");
}