JwksEntity.php in Simple OAuth (OAuth2) & OpenID Connect 5.x
File
src/Entities/JwksEntity.php
View source
<?php
namespace Drupal\simple_oauth\Entities;
class JwksEntity {
public function getKeys() {
$json_data = [];
$config = \Drupal::config('simple_oauth.settings');
if (!empty($config)) {
$public_key_real = \Drupal::service('file_system')
->realpath($config
->get('public_key'));
if (!empty($public_key_real)) {
$key_info = openssl_pkey_get_details(openssl_pkey_get_public(file_get_contents($public_key_real)));
$json_data = [
'keys' => [
[
'kty' => 'RSA',
'n' => rtrim(str_replace([
'+',
'/',
], [
'-',
'_',
], base64_encode($key_info['rsa']['n'])), '='),
'e' => rtrim(str_replace([
'+',
'/',
], [
'-',
'_',
], base64_encode($key_info['rsa']['e'])), '='),
],
],
];
}
}
return $json_data;
}
}