You are here

trait SimpleOauthTestTrait in Simple OAuth (OAuth2) & OpenID Connect 5.x

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/SimpleOauthTestTrait.php \Drupal\Tests\simple_oauth\Functional\SimpleOauthTestTrait
  2. 8.3 tests/src/Functional/SimpleOauthTestTrait.php \Drupal\Tests\simple_oauth\Functional\SimpleOauthTestTrait

Trait with methods needed by tests.

Hierarchy

File

tests/src/Functional/SimpleOauthTestTrait.php, line 8

Namespace

Drupal\Tests\simple_oauth\Functional
View source
trait SimpleOauthTestTrait {
  protected $privateKey = '-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAvPQBbfIu1fZ9Oq/af+KAxnhMRi3BJA9qBqsXLtNUgtkf68wn
8z484j/yj9wLRP49b0K41yoExQ8KUD1D2mSh9C45GCmeBD4dM8KNMs2flSAXFgIV
twABuu+7k+75RIndJo33heADIYf6BKT1Q4nAgDi4pyfvDYjYp5iDyeLNcWiNUo/Y
Y4aKoDH36plUPA+kP1ekjCCPw7jsnV50zvCPbutvO7TZAEve/3SUIqxs0L6eG6Zv
PV2hWAqItXpXiy/WMbtkCjlwGTb60yKmjkAUNyAppSPnclH3h6HdtOzVjXfWkO9H
x3C4OAL7QET3/arRt1GDiWKwfc+Dv04lXDT0AwIDAQABAoIBAGOHgA1C6YrI2LQG
F2kPjVd93GeHCFqPSAEVNBP1O2nlJtxU4KJPIVDn8EP423LPHNszYRvtRS/ruToE
2235Xhm6E1b37QU9FrLCAxBEoY+ypJZyKLAJb9/hEYRd960zlWsOkthQ5DVQY9D4
dzzJHb4soo9iCJivgbfeLWU1c5QNXztUoHZA0zYHbVlfNCvD7cTGJpnnPdZJLd93
lZ1abkBAz6/WMavHnNNKBxPH/8hE8wLaaOZpwqce/RpcJlKM91db6OfrWnpj/Hrd
XJIKbQErrJTXOlBm27+9xoX+btg1GR9JowlUZ+BGoSmO+j0wqVWzHb+NSkbMPf10
uLyE8QkCgYEA7IDz5AYlHvafjwzWWYvU4WHl/w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XFgIVtwABuu+7k+75RIndJo33heADIYf6BKT1Q4nA
gDi4pyfvDYjYp5iDyeLNcWiNUo/YY4aKoDH36plUPA+kP1ekjCCPw7jsnV50zvCP
butvO7TZAEve/3SUIqxs0L6eG6ZvPV2hWAqItXpXiy/WMbtkCjlwGTb60yKmjkAU
NyAppSPnclH3h6HdtOzVjXfWkO9Hx3C4OAL7QET3/arRt1GDiWKwfc+Dv04lXDT0
AwIDAQAB
-----END PUBLIC KEY-----';

  /**
   * Set up public and private keys.
   */
  public function setUpKeys() {
    $public_key_path = 'private://public.key';
    $private_key_path = 'private://private.key';
    file_put_contents($public_key_path, $this->publicKey);
    file_put_contents($private_key_path, $this->privateKey);
    chmod($public_key_path, 0660);
    chmod($private_key_path, 0660);
    $settings = $this
      ->config('simple_oauth.settings');
    $settings
      ->set('public_key', $public_key_path);
    $settings
      ->set('private_key', $private_key_path);
    $settings
      ->save();
  }

  /**
   * Base64 url encode.
   *
   * @param string $string
   *   The string to encode.
   *
   * @return string
   *   The encoded string.
   */
  public static function base64urlencode($string) {
    $base64 = base64_encode($string);
    $base64 = rtrim($base64, "=");
    return strtr($base64, '+/', '-_');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SimpleOauthTestTrait::$privateKey protected property
SimpleOauthTestTrait::$publicKey protected property
SimpleOauthTestTrait::base64urlencode public static function Base64 url encode.
SimpleOauthTestTrait::setUpKeys public function Set up public and private keys.