Auth0\SDK\Helpers\JWKFetcher::fetchKeys PHP Method

fetchKeys() public method

public fetchKeys ( $iss )
    public function fetchKeys($iss)
    {
        $url = "{$iss}.well-known/jwks.json";
        if (($secret = $this->cache->get($url)) === null) {
            $secret = [];
            $request = new RequestBuilder(array('domain' => $iss, 'basePath' => '.well-known/jwks.json', 'method' => 'GET', 'guzzleOptions' => $this->guzzleOptions));
            $jwks = $request->call();
            foreach ($jwks['keys'] as $key) {
                $secret[$key['kid']] = $this->convertCertToPem($key['x5c'][0]);
            }
            $this->cache->set($url, $secret);
        }
        return $secret;
    }

Usage Example

Example #1
0
 public function testFileSystemCache()
 {
     $env = $this->getEnv();
     $cache = new CacheDecorator(new FileSystemCacheHandler(md5(uniqid())));
     $fetcher = new JWKFetcher($cache);
     $keys = $fetcher->fetchKeys($env['DOMAIN']);
     $this->assertTrue(is_array($keys));
     $keys = $fetcher->fetchKeys($env['DOMAIN']);
     $this->assertTrue(is_array($keys));
     $this->assertEquals(2, $cache->count('get'));
     $this->assertEquals(1, $cache->count('set'));
     $this->assertEquals(0, $cache->count('delete'));
     $cache->delete('auth0-php.auth0.com.well-known/jwks.json');
     $keys = $fetcher->fetchKeys($env['DOMAIN']);
     $this->assertTrue(is_array($keys));
     $this->assertEquals(3, $cache->count('get'));
     $this->assertEquals(2, $cache->count('set'));
     $this->assertEquals(1, $cache->count('delete'));
 }