diff --git a/oauth2_server.info.yml b/oauth2_server.info.yml index db1ac72..c6639a5 100644 --- a/oauth2_server.info.yml +++ b/oauth2_server.info.yml @@ -2,5 +2,5 @@ name: OAuth2 Server type: module description: 'Provides OAuth2 server functionality.' package: OAuth2 -core_version_requirement: ^8.8 || ^9 +core_version_requirement: ^8.8 || ^9 || ^10 configure: oauth2_server.overview diff --git a/oauth2_server.module b/oauth2_server.module index fe0deea..b421082 100644 --- a/oauth2_server.module +++ b/oauth2_server.module @@ -20,6 +20,7 @@ function oauth2_server_cron() { $query = \Drupal::entityQuery($entity_type); $query->condition('expires', 0, '<>'); $query->condition('expires', $request_time, '<='); + $query->accessCheck(TRUE); $result = $query->execute(); if ($result) { diff --git a/src/Authentication/Provider/OAuth2DrupalAuthProvider.php b/src/Authentication/Provider/OAuth2DrupalAuthProvider.php index 09416fc..a64bfd5 100644 --- a/src/Authentication/Provider/OAuth2DrupalAuthProvider.php +++ b/src/Authentication/Provider/OAuth2DrupalAuthProvider.php @@ -8,7 +8,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Drupal\oauth2_server\OAuth2StorageInterface; @@ -221,10 +221,10 @@ class OAuth2DrupalAuthProvider implements AuthenticationProviderInterface { * @return bool * Whether the exception s valid or not. */ - public function handleException(GetResponseForExceptionEvent $event) { - $exception = $event->getException(); + public function handleException(ExceptionEvent $event) { + $exception = $event->getThrowable(); if ($exception instanceof AccessDeniedHttpException) { - $event->setException(new UnauthorizedHttpException('Invalid consumer origin.', $exception)); + $event->setThrowable(new UnauthorizedHttpException('Invalid consumer origin.', $exception)); return TRUE; } return FALSE; @@ -264,4 +264,4 @@ class OAuth2DrupalAuthProvider implements AuthenticationProviderInterface { } } -} +} \ No newline at end of file diff --git a/src/Controller/OAuth2Controller.php b/src/Controller/OAuth2Controller.php index 3cb7a2f..a2c8e62 100644 --- a/src/Controller/OAuth2Controller.php +++ b/src/Controller/OAuth2Controller.php @@ -301,9 +301,7 @@ class OAuth2Controller extends ControllerBase { $cert = openssl_x509_read($keys['public_key']); $publicKey = openssl_get_publickey($cert); - openssl_x509_free($cert); $keyDetails = openssl_pkey_get_details($publicKey); - openssl_pkey_free($publicKey); $jwk['e'] = base64_encode($keyDetails['rsa']['e']); $jwk['n'] = base64_encode($keyDetails['rsa']['n']); $jwk['mod'] = self::base64urlEncode($keyDetails['rsa']['n']); diff --git a/src/OAuth2Storage.php b/src/OAuth2Storage.php index 14a8eb2..d66e256 100644 --- a/src/OAuth2Storage.php +++ b/src/OAuth2Storage.php @@ -6,6 +6,7 @@ use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\File\FileUrlGeneratorInterface; use Drupal\Core\Password\PasswordInterface; use Drupal\Core\Session\AnonymousUserSession; use Drupal\user\UserInterface; @@ -54,6 +55,13 @@ class OAuth2Storage implements OAuth2StorageInterface { */ protected $time; + /** + * File URL generator service. + * + * @var \Drupal\Core\File\FileUrlGeneratorInterface + */ + protected $fileUrlGenerator; + /** * Constructs a new OAuth2Storage. * @@ -67,19 +75,27 @@ class OAuth2Storage implements OAuth2StorageInterface { * The config factory. * @param \Drupal\Component\Datetime\TimeInterface $time * The time object. + * @param \Drupal\Core\File\FileUrlGeneratorInterface $fileUrlGenerator + * File URL generator service. */ public function __construct( EntityTypeManagerInterface $entity_type_manager, PasswordInterface $password_hasher, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, - TimeInterface $time + TimeInterface $time, + FileUrlGeneratorInterface $fileUrlGenerator = NULL ) { $this->entityTypeManager = $entity_type_manager; $this->passwordHasher = $password_hasher; $this->moduleHandler = $module_handler; $this->configFactory = $config_factory; $this->time = $time; + if ($fileUrlGenerator === NULL) { + @trigger_error('Calling ' . __METHOD__ . ' without the $fileUrlGenerator argument is deprecated in oauth2_server:2.1.0 and it will be required in oauth2_server:3.0.0. See https://www.drupal.org/node/3288840', E_USER_DEPRECATED); + $fileUrlGenerator = \Drupal::service('file_url_generator'); + } + $this->fileUrlGenerator = $fileUrlGenerator; } /** @@ -419,14 +435,15 @@ class OAuth2Storage implements OAuth2StorageInterface { $uid = 0; } + /** @var \Drupal\oauth2_server\TokenInterface $token */ $token = $this->entityTypeManager->getStorage('oauth2_server_token') ->create(['type' => 'access']); - $token->client_id = $client->id(); - $token->uid = $uid; - $token->token = $access_token; + $token->set('client_id', $client->id()); + $token->set('uid', $uid); + $token->set('token', $access_token); } - $token->expires = $expires; + $token->set('expires', $expires); $this->setScopeData($token, $client->getServer(), $scope); return $token->save(); @@ -509,6 +526,10 @@ class OAuth2Storage implements OAuth2StorageInterface { * The scope string. * @param string|null $id_token * The token string. + * @param string|null $code_challenge + * The code challenge string. + * @param string|null $code_challenge_method + * The code challenge method string. * * @return int * Whether the authorization code could be saved or not. @@ -517,7 +538,7 @@ class OAuth2Storage implements OAuth2StorageInterface { * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException * @throws \Drupal\Core\Entity\EntityStorageException */ - public function setAuthorizationCode($code, $client_id, $uid, $redirect_uri, $expires, $scope = NULL, $id_token = NULL) { + public function setAuthorizationCode($code, $client_id, $uid, $redirect_uri, $expires, $scope = NULL, $id_token = NULL, $code_challenge = NULL, $code_challenge_method = NULL) { /** @var \Drupal\oauth2_server\ClientInterface $client */ $client = $this->getStorageClient($client_id); if (!$client) { @@ -875,11 +896,12 @@ class OAuth2Storage implements OAuth2StorageInterface { throw new \InvalidArgumentException("The supplied user couldn't be loaded."); } + /** @var \Drupal\oauth2_server\TokenInterface $token */ $token = $this->entityTypeManager->getStorage('oauth2_server_token') ->create(['type' => 'refresh']); - $token->client_id = $client->id(); - $token->uid = $uid; - $token->token = $refresh_token; + $token->set('client_id', $client->id()); + $token->set('uid', $uid); + $token->set('token', $refresh_token); } $token->expires = $expires; @@ -1011,7 +1033,7 @@ class OAuth2Storage implements OAuth2StorageInterface { $file->getEntityTypeId() === 'file' && $file->access('download') ) { - return Url::fromUri(file_create_url($file->getFileUri()))->toString(); + return $this->fileUrlGenerator->generate($file->getFileUri())->toString(); } } } diff --git a/src/ScopeUtility.php b/src/ScopeUtility.php index 5c73602..928682b 100644 --- a/src/ScopeUtility.php +++ b/src/ScopeUtility.php @@ -123,7 +123,7 @@ class ScopeUtility implements OAuth2ScopeInterface { public function getDefaultScope($client_id = NULL) { // Allow any hook_oauth2_server_default_scope() implementations to supply // the default scope. The first one to return a scope wins. - foreach (\Drupal::moduleHandler()->getImplementations('oauth2_server_default_scope') as $module) { + foreach (\Drupal::moduleHandler()->invokeAllWith('oauth2_server_default_scope') as $module) { $function = $module . '_' . 'oauth2_server_default_scope'; $args = [$this->server]; $result = call_user_func_array($function, $args); diff --git a/src/Utility.php b/src/Utility.php index c4293b4..a8ca13b 100644 --- a/src/Utility.php +++ b/src/Utility.php @@ -116,7 +116,7 @@ class Utility { * - public_key: The generated public key certificate (PEM encoded X.509). */ public static function generateKeys() { - $module_path = drupal_get_path('module', 'oauth2_server'); + $module_path = \Drupal::service('extension.list.module')->getPath('oauth2_server'); $module_realpath = \Drupal::service('file_system')->realpath($module_path); $config = [ 'config' => $module_realpath . DIRECTORY_SEPARATOR . 'oauth2_server.openssl.cnf', diff --git a/tests/src/Functional/OAuth2ServerAdminTest.php b/tests/src/Functional/OAuth2ServerAdminTest.php index 104eac8..8a4fb63 100644 --- a/tests/src/Functional/OAuth2ServerAdminTest.php +++ b/tests/src/Functional/OAuth2ServerAdminTest.php @@ -21,7 +21,7 @@ class OAuth2ServerAdminTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['oauth2_server']; + protected static $modules = ['oauth2_server']; /** * Test editing client secret. @@ -37,9 +37,10 @@ class OAuth2ServerAdminTest extends BrowserTestBase { $this->drupalLogin($account); $server_id = strtolower($this->randomMachineName()); + $this->drupalGet(new Url('entity.oauth2_server.add_form')); // Create a server in the UI. - $this->drupalPostForm(new Url('entity.oauth2_server.add_form'), [ + $this->submitForm([ 'name' => $this->randomString(), 'server_id' => $server_id, ], t('Save server')); @@ -47,7 +48,8 @@ class OAuth2ServerAdminTest extends BrowserTestBase { // Create a client of the server in the UI, with a random secret. $client_id = strtolower($this->randomMachineName()); $secret = $this->randomString(32); - $this->drupalPostForm(new Url('entity.oauth2_server.clients.add_form', ['oauth2_server' => $server_id]), [ + $this->drupalGet(new Url('entity.oauth2_server.clients.add_form', ['oauth2_server' => $server_id])); + $this->submitForm([ 'name' => $this->randomString(), 'client_id' => $client_id, 'redirect_uri' => 'http://localhost', @@ -58,7 +60,7 @@ class OAuth2ServerAdminTest extends BrowserTestBase { // Test that the raw secret does not match the saved (hashed) one. /** @var \Drupal\oauth2_server\ClientInterface $client */ $client = $entity_type_manager->getStorage('oauth2_server_client')->load($client_id); - $this->assertNotEqual($secret, $client->client_secret, 'Raw secret does not match hashed secret.'); + $this->assertNotEquals($secret, $client->client_secret, 'Raw secret does not match hashed secret.'); // Test that the secret can be matched. $this->assertTrue($password_hasher->check($secret, $client->client_secret), 'Hashes match for known secret and stored secret.'); @@ -70,7 +72,7 @@ class OAuth2ServerAdminTest extends BrowserTestBase { ]); $entity_type_manager->getStorage('oauth2_server_client')->resetCache(); $client = $entity_type_manager->getStorage('oauth2_server_client')->load($client_id); - $this->assertEqual($old_hashed_secret, $client->client_secret, 'Secret is not changed accidentally when editing the client.'); + $this->assertEquals($old_hashed_secret, $client->client_secret, 'Secret is not changed accidentally when editing the client.'); // Edit the client, and set an empty secret. $this->updateClient($client, [ @@ -104,7 +106,8 @@ class OAuth2ServerAdminTest extends BrowserTestBase { 'oauth2_server' => $client->getServer()->id(), 'oauth2_server_client' => $client->id(), ]); - $this->drupalPostForm($edit_uri, $values, t('Save client')); + $this->drupalGet($edit_uri); + $this->submitForm($values, t('Save client')); } } diff --git a/tests/src/Functional/OAuth2ServerStorageTest.php b/tests/src/Functional/OAuth2ServerStorageTest.php index e6b42d4..4e97245 100644 --- a/tests/src/Functional/OAuth2ServerStorageTest.php +++ b/tests/src/Functional/OAuth2ServerStorageTest.php @@ -19,7 +19,7 @@ class OAuth2ServerStorageTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['oauth2_server']; + protected static $modules = ['oauth2_server']; /** * The client key of the test client. @@ -59,7 +59,7 @@ class OAuth2ServerStorageTest extends BrowserTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->redirectUri = $this->buildUrl('authorized', ['absolute' => TRUE]); @@ -166,10 +166,10 @@ class OAuth2ServerStorageTest extends BrowserTestBase { $this->assertArrayHasKey('client_id', $token, 'The "client_id" value is present in the token array.'); $this->assertArrayHasKey('user_id', $token, 'The "user_id" value is present in the token array.'); $this->assertArrayHasKey('expires', $token, 'The "expires" value is present in the token array.'); - $this->assertEqual($token['access_token'], 'newtoken', 'The "access_token" key has the expected value.'); - $this->assertEqual($token['client_id'], $this->clientId, 'The "client_id" key has the expected value.'); - $this->assertEqual($token['user_id'], $user->id(), 'The "user_id" key has the expected value.'); - $this->assertEqual($token['expires'], $expires, 'The "expires" key has the expected value.'); + $this->assertEquals($token['access_token'], 'newtoken', 'The "access_token" key has the expected value.'); + $this->assertEquals($token['client_id'], $this->clientId, 'The "client_id" key has the expected value.'); + $this->assertEquals($token['user_id'], $user->id(), 'The "user_id" key has the expected value.'); + $this->assertEquals($token['expires'], $expires, 'The "expires" key has the expected value.'); // Update the token. $expires = time() + 42; @@ -178,7 +178,7 @@ class OAuth2ServerStorageTest extends BrowserTestBase { $token = $this->storage->getAccessToken('newtoken'); $this->assertTrue((bool) $token, 'An access token was successfully returned.'); - $this->assertEqual($token['expires'], $expires, 'The expires timestamp matches the new value.'); + $this->assertEquals($token['expires'], $expires, 'The expires timestamp matches the new value.'); } /** @@ -201,10 +201,10 @@ class OAuth2ServerStorageTest extends BrowserTestBase { $this->assertArrayHasKey('client_id', $token, 'The "client_id" value is present in the token array.'); $this->assertArrayHasKey('user_id', $token, 'The "user_id" value is present in the token array.'); $this->assertArrayHasKey('expires', $token, 'The "expires" value is present in the token array.'); - $this->assertEqual($token['refresh_token'], 'refreshtoken', 'The "refresh_token" key has the expected value.'); - $this->assertEqual($token['client_id'], $this->clientId, 'The "client_id" key has the expected value.'); - $this->assertEqual($token['user_id'], $user->id(), 'The "user_id" key has the expected value.'); - $this->assertEqual($token['expires'], $expires, 'The "expires" key has the expected value.'); + $this->assertEquals($token['refresh_token'], 'refreshtoken', 'The "refresh_token" key has the expected value.'); + $this->assertEquals($token['client_id'], $this->clientId, 'The "client_id" key has the expected value.'); + $this->assertEquals($token['user_id'], $user->id(), 'The "user_id" key has the expected value.'); + $this->assertEquals($token['expires'], $expires, 'The "expires" key has the expected value.'); } /** @@ -228,11 +228,11 @@ class OAuth2ServerStorageTest extends BrowserTestBase { $this->assertArrayHasKey('user_id', $code, 'The "user_id" value is present in the code array.'); $this->assertArrayHasKey('redirect_uri', $code, 'The "redirect_uri" value is present in the code array.'); $this->assertArrayHasKey('expires', $code, 'The "expires" value is present in the code array.'); - $this->assertEqual($code['authorization_code'], 'newcode', 'The "authorization_code" key has the expected value.'); - $this->assertEqual($code['client_id'], $this->clientId, 'The "client_id" key has the expected value.'); - $this->assertEqual($code['user_id'], $user->id(), 'The "user_id" key has the expected value.'); - $this->assertEqual($code['redirect_uri'], 'http://example.com', 'The "redirect_uri" key has the expected value.'); - $this->assertEqual($code['expires'], $expires, 'The "expires" key has the expected value.'); + $this->assertEquals($code['authorization_code'], 'newcode', 'The "authorization_code" key has the expected value.'); + $this->assertEquals($code['client_id'], $this->clientId, 'The "client_id" key has the expected value.'); + $this->assertEquals($code['user_id'], $user->id(), 'The "user_id" key has the expected value.'); + $this->assertEquals($code['redirect_uri'], 'http://example.com', 'The "redirect_uri" key has the expected value.'); + $this->assertEquals($code['expires'], $expires, 'The "expires" key has the expected value.'); // Change an existing code. $expires = time() + 42; @@ -241,7 +241,7 @@ class OAuth2ServerStorageTest extends BrowserTestBase { $code = $this->storage->getAuthorizationCode('newcode'); $this->assertTrue((bool) $code, 'An authorization code was successfully returned.'); - $this->assertEqual($code['expires'], $expires, 'The expires timestamp matches the new value.'); + $this->assertEquals($code['expires'], $expires, 'The expires timestamp matches the new value.'); } /** diff --git a/tests/src/Functional/OAuth2ServerTest.php b/tests/src/Functional/OAuth2ServerTest.php index c622477..eebda51 100644 --- a/tests/src/Functional/OAuth2ServerTest.php +++ b/tests/src/Functional/OAuth2ServerTest.php @@ -26,7 +26,7 @@ class OAuth2ServerTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['oauth2_server', 'oauth2_server_test']; + protected static $modules = ['oauth2_server', 'oauth2_server_test']; /** * The client key of the test client. @@ -99,7 +99,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->redirectUri = $this->buildUrl('/user', ['absolute' => TRUE]); @@ -203,7 +203,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV $this->drupalLogin($user); $response = $this->authorizationCodeRequest('token'); - $this->assertEqual($response->getStatusCode(), 302, 'The implicit flow request completed successfully'); + $this->assertEquals($response->getStatusCode(), 302, 'The implicit flow request completed successfully'); $parameters = $this->getRedirectParams($response, '#'); $this->assertTokenResponse($parameters, FALSE); @@ -214,10 +214,10 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV $response = $this->httpGetRequest($verification_url); $verification_response = json_decode($response->getBody()); - $this->assertEqual($response->getStatusCode(), 200, 'The provided access token was successfully verified.'); - $this->verbose($verification_response->scope); - $this->verbose(urldecode($parameters['scope'])); - $this->assertEqual($verification_response->scope, urldecode($parameters['scope']), 'The provided scope matches the scope of the verified access token.'); + $this->assertEquals($response->getStatusCode(), 200, 'The provided access token was successfully verified.'); + dump($verification_response->scope); + dump(urldecode($parameters['scope'])); + $this->assertEquals($verification_response->scope, urldecode($parameters['scope']), 'The provided scope matches the scope of the verified access token.'); } } @@ -240,7 +240,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV ]; $response = $this->httpPostRequest($token_url, $data); - $this->assertEqual($response->getStatusCode(), 200, 'The token request completed successfully'); + $this->assertEquals($response->getStatusCode(), 200, 'The token request completed successfully'); $payload = json_decode($response->getBody()); $this->assertTokenResponse($payload); @@ -258,7 +258,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV ]; $response = $this->httpPostRequest($token_url, $data); - $this->assertEqual($response->getStatusCode(), 200, 'The token request completed successfully'); + $this->assertEquals($response->getStatusCode(), 200, 'The token request completed successfully'); $payload = json_decode($response->getBody()); $this->assertTokenResponse($payload, FALSE); } @@ -290,7 +290,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV ]; $response = $this->httpPostRequest($token_url, $data, FALSE); - $this->assertEqual($response->getStatusCode(), 200, 'The token request completed successfully'); + $this->assertEquals($response->getStatusCode(), 200, 'The token request completed successfully'); $payload = json_decode($response->getBody()); $this->assertTokenResponse($payload, FALSE); } @@ -300,7 +300,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV */ public function testPasswordGrantType() { $response = $this->passwordGrantRequest(); - $this->assertEqual($response->getStatusCode(), 200, 'The token request completed successfully'); + $this->assertEquals($response->getStatusCode(), 200, 'The token request completed successfully'); $payload = json_decode($response->getBody()); $this->assertTokenResponse($payload); } @@ -321,7 +321,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV ]; $response = $this->httpPostRequest($token_url, $data); - $this->assertEqual($response->getStatusCode(), 200, 'The token request completed successfully'); + $this->assertEquals($response->getStatusCode(), 200, 'The token request completed successfully'); $payload = json_decode($response->getBody()); // The response will include a new refresh_token because // always_issue_new_refresh_token is TRUE. @@ -335,7 +335,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV // The default scope returned by oauth2_server_default_scope(). $response = $this->passwordGrantRequest(); $payload = json_decode($response->getBody()); - $this->assertEqual($payload->scope, 'admin basic', 'The correct default scope was returned.'); + $this->assertEquals($payload->scope, 'admin basic', 'The correct default scope was returned.'); // A non-existent scope. try { @@ -343,7 +343,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV } catch (ClientException $e) { if ($e->hasResponse()) { - $this->assertEqual($e->getResponse()->getStatusCode(), 400, 'Invalid scope correctly detected.'); + $this->assertEquals($e->getResponse()->getStatusCode(), 400, 'Invalid scope correctly detected.'); } } @@ -354,14 +354,14 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV } catch (ClientException $e) { if ($e->hasResponse()) { - $this->assertEqual($e->getResponse()->getStatusCode(), 400, 'Inaccessible scope correctly detected.'); + $this->assertEquals($e->getResponse()->getStatusCode(), 400, 'Inaccessible scope correctly detected.'); } } // A specific requested scope. $response = $this->passwordGrantRequest('admin'); $payload = json_decode($response->getBody()); - $this->assertEqual($payload->scope, 'admin', 'The correct scope was returned.'); + $this->assertEquals($payload->scope, 'admin', 'The correct scope was returned.'); } /** @@ -385,7 +385,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV ]; $response = $this->httpPostRequest($token_url, $data); - $this->assertEqual($response->getStatusCode(), 200, 'The token request completed successfully'); + $this->assertEquals($response->getStatusCode(), 200, 'The token request completed successfully'); $payload = json_decode($response->getBody()); $this->assertTokenResponse($payload, FALSE); if (!empty($payload->id_token)) { @@ -409,7 +409,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV ]; $response = $this->httpPostRequest($token_url, $data); - $this->assertEqual($response->getStatusCode(), 200, 'The token request completed successfully'); + $this->assertEquals($response->getStatusCode(), 200, 'The token request completed successfully'); $payload = json_decode($response->getBody()); $this->assertTokenResponse($payload); if (!empty($payload->id_token)) { @@ -427,7 +427,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV $account = $this->drupalCreateUser(['use oauth2 server']); $this->drupalLogin($account); $response = $this->authorizationCodeRequest('id_token', 'openid email'); - $this->assertEqual($response->getStatusCode(), 302, 'The "id_token" implicit flow request completed successfully'); + $this->assertEquals($response->getStatusCode(), 302, 'The "id_token" implicit flow request completed successfully'); $parameters = $this->getRedirectParams($response, '#'); if (!empty($parameters['id_token'])) { $this->assertIdToken($parameters['id_token'], FALSE, $account); @@ -437,7 +437,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV } $response = $this->authorizationCodeRequest('token id_token', 'openid email profile phone'); - $this->assertEqual($response->getStatusCode(), 302, 'The "token id_token" implicit flow request completed successfully'); + $this->assertEquals($response->getStatusCode(), 302, 'The "token id_token" implicit flow request completed successfully'); $parameters = $this->getRedirectParams($response, '#'); $this->assertTokenResponse($parameters, FALSE); if (!empty($parameters['id_token'])) { @@ -471,7 +471,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV ]; foreach ($expected_claims as $claim => $expected_value) { - $this->assertEqual($payload->$claim, $expected_value, 'The UserInfo endpoint returned a valid "' . $claim . '" claim'); + $this->assertEquals($payload->$claim, $expected_value, 'The UserInfo endpoint returned a valid "' . $claim . '" claim'); } } @@ -490,7 +490,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV $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.'); + $this->assertEquals($this->loggedInUser->name->value, $payload['sub'], 'The UserInfo "sub" is now the user\'s name.'); } /** @@ -518,7 +518,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV $parts = explode('.', $payload->id_token); $claims = json_decode(Utility::base64urlDecode($parts[1]), TRUE); - $this->assertEqual($this->loggedInUser->name->value, $claims['sub'], 'The ID token "sub" is now the user\'s name.'); + $this->assertEquals($this->loggedInUser->name->value, $claims['sub'], 'The ID token "sub" is now the user\'s name.'); } /** @@ -531,7 +531,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV $server->save(); $response = $this->passwordGrantRequest(); - $this->assertEqual($response->getStatusCode(), 200, 'The token request completed successfully'); + $this->assertEquals($response->getStatusCode(), 200, 'The token request completed successfully'); $payload = json_decode($response->getBody()); // The refresh token is contained inside the crypto token. $this->assertTokenResponse($payload, FALSE); @@ -565,7 +565,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV } catch (ClientException $e) { if ($e->hasResponse()) { - $this->assertEqual($e->getResponse()->getStatusCode(), 401, 'Missing access token correctly detected.'); + $this->assertEquals($e->getResponse()->getStatusCode(), 401, 'Missing access token correctly detected.'); } } @@ -579,7 +579,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV } catch (ClientException $e) { if ($e->hasResponse()) { - $this->assertEqual($e->getResponse()->getStatusCode(), 403, 'Insufficient scope correctly detected.'); + $this->assertEquals($e->getResponse()->getStatusCode(), 403, 'Insufficient scope correctly detected.'); } } @@ -631,7 +631,7 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV } catch (ClientException $e) { if ($e->hasResponse()) { - $this->assertEqual($e->getResponse()->getStatusCode(), 403, 'A blocked user is denied access with 403 Forbidden.'); + $this->assertEquals($e->getResponse()->getStatusCode(), 403, 'A blocked user is denied access with 403 Forbidden.'); } } } @@ -694,10 +694,10 @@ IJpQWcPiClejygMqUb8ZAkEA6SFArj46gwFaERr+D8wMizfZdxhzEuMMG3angAuV $this->assertArrayHasKey('email_verified', $claims, 'The id_token contains an "email_verified" claim.'); } - $this->assertEqual($claims['aud'], $this->clientId, 'The id_token "aud" claim contains the expected client_id.'); - $this->assertEqual($claims['nonce'], 'test', 'The id_token "nonce" claim contains the expected nonce.'); + $this->assertEquals($claims['aud'], $this->clientId, 'The id_token "aud" claim contains the expected client_id.'); + $this->assertEquals($claims['nonce'], 'test', 'The id_token "nonce" claim contains the expected nonce.'); if ($account) { - $this->assertEqual($claims['email'], $account->mail->getValue()[0]['value']); + $this->assertEquals($claims['email'], $account->mail->getValue()[0]['value']); } }