[ 'class' => NginxCache::class, 'rules' => [ 'index' => 3600, // 1h ], ], ]); } public function actionIndex(): array { return [ 'keys' => array_map(fn(array $jwk): array => [ 'alg' => $jwk['alg'], 'kid' => $jwk['kid'], 'pem' => self::convertJwkToPem($jwk), ], Yii::$app->tokens->getJwks()['keys']), ]; } /** * @param array $jwk */ private static function convertJwkToPem(array $jwk): string { Assert::same($jwk['kty'] ?? null, 'EC'); Assert::same($jwk['crv'] ?? null, 'P-256'); $key = openssl_pkey_new([ 'ec' => [ 'curve_name' => 'prime256v1', 'x' => Base64UrlSafe::decode($jwk['x']), 'y' => Base64UrlSafe::decode($jwk['y']), ], ]); Assert::notFalse($key); $details = openssl_pkey_get_details($key); Assert::isArray($details); return $details['key']; } }