You are here

public function OAuth2ServerTest::testOpenIdConnectNonDefaultSub in OAuth2 Server 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Functional/OAuth2ServerTest.php \Drupal\Tests\oauth2_server\Functional\OAuth2ServerTest::testOpenIdConnectNonDefaultSub()

Tests that the OpenID Connect 'sub' property affects user info 'sub' claim.

File

tests/src/Functional/OAuth2ServerTest.php, line 481

Class

OAuth2ServerTest
The OAuth2 Server admin test case.

Namespace

Drupal\Tests\oauth2_server\Functional

Code

public function testOpenIdConnectNonDefaultSub() {
  $this
    ->config('oauth2_server.oauth')
    ->set('user_sub_property', 'name')
    ->save();
  $response = $this
    ->passwordGrantRequest('openid');
  $payload = json_decode($response
    ->getBody());
  $access_token = $payload->access_token;
  $query = [
    'access_token' => $access_token,
  ];
  $info_url = $this
    ->buildUrl(new Url('oauth2_server.userinfo'), [
    'query' => $query,
  ]);
  $response = $this
    ->httpGetRequest($info_url);
  $payload = json_decode($response
    ->getBody(), TRUE);
  $this
    ->assertEqual($this->loggedInUser->name->value, $payload['sub'], 'The UserInfo "sub" is now the user\'s name.');
}