You are here

public function JWKFetcher::getKeys in Auth0 Single Sign On 8.2

Gets an array of keys from the JWKS as kid => x5c.

Parameters

string $jwks_url Full URL to the JWKS.:

Return value

array

File

vendor/auth0/auth0-php/src/Helpers/JWKFetcher.php, line 72

Class

JWKFetcher
Class JWKFetcher.

Namespace

Auth0\SDK\Helpers

Code

public function getKeys($jwks_url) {
  $keys = $this->cache
    ->get($jwks_url);
  if (is_array($keys) && !empty($keys)) {
    return $keys;
  }
  $jwks = $this
    ->requestJwks($jwks_url);
  if (empty($jwks) || empty($jwks['keys'])) {
    return [];
  }
  $keys = [];
  foreach ($jwks['keys'] as $key) {
    if (empty($key['kid']) || empty($key['x5c']) || empty($key['x5c'][0])) {
      continue;
    }
    $keys[$key['kid']] = $this
      ->convertCertToPem($key['x5c'][0]);
  }
  $this->cache
    ->set($jwks_url, $keys);
  return $keys;
}