You are here

public function Auth0Test::testThatExchangeSucceedsWithNoIdToken in Auth0 Single Sign On 8.2

Test that the exchanges succeeds when there is only an access token.

Throws

ApiException

CoreException

File

vendor/auth0/auth0-php/tests/Auth0Test.php, line 104

Class

Auth0Test
Class Auth0Test

Namespace

Auth0\Tests

Code

public function testThatExchangeSucceedsWithNoIdToken() {
  $mock = new MockHandler([
    // Code exchange response.
    // Respond with no ID token, access token with correct number of segments.
    new Response(200, self::$headers, '{"access_token":"1.2.3","refresh_token":"4.5.6"}'),
    // Userinfo response.
    new Response(200, self::$headers, '{"sub":"123"}'),
  ]);
  $add_config = [
    'scope' => 'offline_access read:messages',
    'audience' => 'https://api.identifier',
    'guzzle_options' => [
      'handler' => HandlerStack::create($mock),
    ],
  ];
  $auth0 = new Auth0(self::$baseConfig + $add_config);
  $_GET['code'] = uniqid();
  $this
    ->assertTrue($auth0
    ->exchange());
  $this
    ->assertEquals([
    'sub' => '123',
  ], $auth0
    ->getUser());
  $this
    ->assertEquals('1.2.3', $auth0
    ->getAccessToken());
  $this
    ->assertEquals('4.5.6', $auth0
    ->getRefreshToken());
}