You are here

function OAuth2ServerTestCase::testImplicitFlow in OAuth2 Server 7

Tests the implicit flow.

File

tests/oauth2_server.test, line 209
OAuth2 tests.

Class

OAuth2ServerTestCase
Test basic API.

Code

function testImplicitFlow() {
  $user = $this
    ->drupalCreateUser(array(
    'use oauth2 server',
  ));
  $this
    ->drupalLogin($user);
  $result = $this
    ->authorizationCodeRequest('token');
  $this
    ->assertEqual($result->code, 302, 'The implicit flow request completed successfully');
  $redirect_url_parts = explode('#', $result->redirect_url);
  $response = drupal_get_query_array($redirect_url_parts[1]);
  $this
    ->assertTokenResponse($response, FALSE);

  // We have received an access token. Verify it.
  // See http://drupal.org/node/1958718.
  if (!empty($response['access_token'])) {
    $verification_url = url('oauth2/tokens/' . $response['access_token'], array(
      'absolute' => TRUE,
    ));
    $result = $this
      ->httpRequest($verification_url);
    $verification_response = json_decode($result->data);
    $this
      ->assertEqual($result->code, 200, 'The provided access token was successfully verified.');
    $this
      ->assertEqual($verification_response->scope, urldecode($response['scope']), 'The provided scope matches the scope of the verified access token.');
  }
}