You are here

public function ImplicitFunctionalTest::testValidClientImplicitGrant in Simple OAuth (OAuth2) & OpenID Connect 5.x

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/ImplicitFunctionalTest.php \Drupal\Tests\simple_oauth\Functional\ImplicitFunctionalTest::testValidClientImplicitGrant()

Test the valid Implicit grant if the client is non 3rd party.

File

tests/src/Functional/ImplicitFunctionalTest.php, line 99

Class

ImplicitFunctionalTest
The implicit tests.

Namespace

Drupal\Tests\simple_oauth\Functional

Code

public function testValidClientImplicitGrant() {
  $this->client
    ->set('third_party', FALSE);
  $this->client
    ->save();
  $valid_params = [
    'response_type' => 'token',
    'client_id' => $this->client
      ->uuid(),
    'client_secret' => $this->clientSecret,
  ];

  // 1. Anonymous request invites the user to log in.
  $this
    ->drupalGet($this->authorizeUrl
    ->toString(), [
    'query' => $valid_params,
  ]);
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->buttonExists('Log in');

  // 2. Log the user in and try again.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet($this->authorizeUrl
    ->toString(), [
    'query' => $valid_params,
  ]);
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->responseContains('Fatal error. Unable to get the authorization server.');
  $this
    ->config('simple_oauth.settings')
    ->set('use_implicit', TRUE)
    ->save();
  $this
    ->drupalGet($this->authorizeUrl
    ->toString(), [
    'query' => $valid_params,
  ]);
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->addressMatches('/\\/oauth\\/test#access_token=.*&token_type=Bearer&expires_in=\\d*/');
}