You are here

public function OAuth2ClientTest::serverSideFlow in OAuth2 Client 8

Test the server-side flow.

For this test we are using 'client2' which has automatic authorization enabled.

1 call to OAuth2ClientTest::serverSideFlow()
OAuth2ClientTest::testGetAccessToken in tests/src/Functional/OAuth2ClientTest.php

File

tests/src/Functional/OAuth2ClientTest.php, line 95

Class

OAuth2ClientTest
Test OAuth2 Client.

Namespace

Drupal\Tests\oauth2_client\Functional

Code

public function serverSideFlow() {
  $users = $this->userStorage
    ->loadByProperties([
    'name' => 'user1',
  ]);
  $user = reset($users);
  $this
    ->drupalLogin($user);
  $token1 = $this
    ->getToken('server-side-auto');
  $token2 = $this
    ->getToken('server-side-auto');
  $this
    ->assertEquals($token2, $token1, 'The same cached token is used, while it has not expired yet.');

  // Wait for the token to expire.
  sleep(10);
  $token3 = $this
    ->getToken('server-side-auto');
  $this
    ->assertNotEquals($token3, $token1, 'Getting a new token from refresh_token.');

  // Wait for the refresh_token to expire.
  sleep(30);
  $token4 = $this
    ->getToken('server-side-auto');
}