You are here

class JwksEntity in Simple OAuth (OAuth2) & OpenID Connect 5.x

A JSON Web Key Store entity.

Hierarchy

Expanded class hierarchy of JwksEntity

1 file declares its use of JwksEntity
Jwks.php in src/Controller/Jwks.php

File

src/Entities/JwksEntity.php, line 8

Namespace

Drupal\simple_oauth\Entities
View source
class JwksEntity {

  /**
   * Returns the keys in JWK (JSON Web Key) format.
   *
   * @see https://tools.ietf.org/html/rfc7517
   *
   * @return array
   *   List of keys.
   */
  public function getKeys() {
    $json_data = [];

    // Get the public key from simple_oauth settings.
    $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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JwksEntity::getKeys public function Returns the keys in JWK (JSON Web Key) format.