You are here

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

Test that the skip_userinfo config option uses the ID token instead of calling /userinfo.

Throws

ApiException

CoreException

File

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

Class

Auth0Test
Class Auth0Test

Namespace

Auth0\Tests

Code

public function testThatExchangeSkipsUserinfo() {
  $id_token_payload = [
    'sub' => 'correct_sub',
  ];
  $id_token = JWT::encode($id_token_payload, '__test_client_secret__');
  $mock = new MockHandler([
    // Code exchange response.
    new Response(200, self::$headers, '{"access_token":"1.2.3","id_token":"' . $id_token . '"}'),
  ]);
  $add_config = [
    'scope' => 'openid',
    'skip_userinfo' => true,
    'guzzle_options' => [
      'handler' => HandlerStack::create($mock),
    ],
  ];
  $auth0 = new Auth0(self::$baseConfig + $add_config);
  $_GET['code'] = uniqid();
  $this
    ->assertTrue($auth0
    ->exchange());
  $this
    ->assertEquals([
    'sub' => 'correct_sub',
  ], $auth0
    ->getUser());
  $this
    ->assertEquals($id_token, $auth0
    ->getIdToken());
  $this
    ->assertEquals('1.2.3', $auth0
    ->getAccessToken());
}