You are here

private function AuthenticationOAuthTest::serverOauthSetup in Entity Share 8.3

Helper function: creates needed server-side entities needed for OAuth.

1 call to AuthenticationOAuthTest::serverOauthSetup()
AuthenticationOAuthTest::createAuthenticationPlugin in modules/entity_share_client/tests/src/Functional/AuthenticationOAuthTest.php
Helper function to create the authentication plugin.

File

modules/entity_share_client/tests/src/Functional/AuthenticationOAuthTest.php, line 353

Class

AuthenticationOAuthTest
Functional test class for import with "OAuth" authorization.

Namespace

Drupal\Tests\entity_share_client\Functional

Code

private function serverOauthSetup() {

  // Create OAuth roles and assign these roles to users.
  $this->clientRole = Role::create([
    'id' => $this
      ->getRandomGenerator()
      ->name(8, TRUE),
    'label' => $this
      ->getRandomGenerator()
      ->word(5),
    'is_admin' => FALSE,
  ]);
  $this->clientRole
    ->grantPermission('grant simple_oauth codes');
  $this->clientRole
    ->grantPermission('entity_share_server_access_channels');
  $this->clientRole
    ->grantPermission('bypass node access');
  $this->clientRole
    ->save();
  $this->adminUser
    ->addRole($this->clientRole
    ->id());
  $this->clientRolePlain = Role::create([
    'id' => $this
      ->getRandomGenerator()
      ->name(8, TRUE),
    'label' => $this
      ->getRandomGenerator()
      ->word(5),
    'is_admin' => FALSE,
  ]);
  $this->clientRolePlain
    ->grantPermission('grant simple_oauth codes');
  $this->clientRolePlain
    ->grantPermission('entity_share_server_access_channels');
  $this->clientRolePlain
    ->save();
  $this->channelUser
    ->addRole($this->clientRolePlain
    ->id());

  // Create client secret.
  $this->clientSecret = $this
    ->getRandomGenerator()
    ->string();

  // Create OAuth consumers.
  $this
    ->createOauthConsumer($this->adminUser, $this->clientRole);
  $this
    ->createOauthConsumer($this->channelUser, $this->clientRolePlain);

  // Create private and public keys for the OAuth module.
  // Not to be confused with Key module's storage of credentials.
  $this
    ->setUpKeys();
}