Several warning and deprecated functions for PHP > 8.0

Created on 7 June 2023, over 1 year ago
Updated 2 May 2024, 5 months ago

Problem/Motivation

Warning 1:

Warning: foreach() argument must be of type array|object, null given in Drupal\openid_connect\OpenIDConnectClaims->getScopes() (line 122 of /code/docroot/modules/contrib/openid_connect/src/OpenIDConnectClaims.php)
#0 /code/docroot/core/includes/bootstrap.inc(158): _drupal_error_handler_real(2, 'foreach() argum...', '/code/docroot/m...', 122)
#1 /code/docroot/modules/contrib/openid_connect/src/OpenIDConnectClaims.php(122): _drupal_error_handler(2, 'foreach() argum...', '/code/docroot/m...', 122)

Warning 2:

Warning: foreach() argument must be of type array|object, null given in Drupal\openid_connect\OpenIDConnect->saveUserinfo() (line 692 of /code/docroot/modules/contrib/openid_connect/src/OpenIDConnect.php)
#0 /code/docroot/core/includes/bootstrap.inc(158): _drupal_error_handler_real(2, 'foreach() argum...', '/code/docroot/m...', 692)
#1 /code/docroot/modules/contrib/openid_connect/src/OpenIDConnect.php(692): _drupal_error_handler(2, 'foreach() argum...', '/code/docroot/m...', 692)
#2 /code/docroot/modules/contrib/openid_connect/src/OpenIDConnect.php(352): Drupal\openid_connect\OpenIDConnect->saveUserinfo(Object(Drupal\user\Entity\User), Array)

Warning 3:

Message Warning: Trying to access array offset on value of type null in Drupal\openid_connect\Form\OpenIDConnectSettingsForm->buildForm() (line 202 of /code/docroot/modules/contrib/openid_connect/src/Form/OpenIDConnectSettingsForm.php)
#0 /code/docroot/core/includes/bootstrap.inc(158): _drupal_error_handler_real(2, 'Trying to acces...', '/code/docroot/m...', 202)
#1 /code/docroot/modules/contrib/openid_connect/src/Form/OpenIDConnectSettingsForm.php(202): _drupal_error_handler(2, 'Trying to acces...', '/code/docroot/m...', 202)

Warning 4:

Steps to reproduce

No special case, just using the module along with the openid_connect_windows_aad.

Proposed resolution

Warning 1:

public function getScopes(OpenIDConnectClientInterface $client = NULL): string {
// If a client was provided, get the scopes from it.
$scopes = !empty($client) ? $client->getClientScopes() : $this->defaultScopes;

$claims_info = $this->getClaims();
$claims = $this->configFactory->getEditable('openid_connect.settings')->get('userinfo_mappings');
if (is_array($claims)) {
foreach ($claims as $claim) {
if (isset($claims_info[$claim]) && !in_array($claims_info[$claim]['scope'], $scopes)) {
$scopes[] = $claims_info[$claim]['scope'];
}
}
}
return implode(' ', $scopes);
}

Warning 2:

// Map groups to Drupal roles.
if (isset($userinfo['groups'])) {
$role_mappings = $this->configFactory->get('openid_connect.settings')->get('role_mappings');

if (is_array($role_mappings) || is_object($role_mappings)) {
foreach ($role_mappings as $role => $mappings) {
if (!empty(array_intersect($mappings, $userinfo['groups']))) {
// User has a mapped role. Add it to their account.
$account->addRole($role);
}
else {
// User doesn't have a mapped role. Remove it from their account.
$account->removeRole($role);
}
}
}
}

Warning 3:

$form['userinfo_mappings'][$property_name] = [
'#type' => 'select',
'#title' => $property->getLabel(),
'#description' => $property->getDescription(),
'#options' => (array) $claims,
'#empty_value' => '',
'#empty_option' => $this->t('- No mapping -'),
'#default_value' => isset($mappings[$property_name]) ? $mappings[$property_name] : '', //fix, If it doesn't exist, it assigns an empty string as a default value.
];
}

Warning 4:

$redirect = Url::fromUri('internal:/' . ltrim($destination ?? '', '/'), ['language' => $language])->toString();

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

🇪🇸Spain eduardo.arana

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @eduardo.arana
  • Status changed to Closed: duplicate over 1 year ago
  • Status changed to Needs review over 1 year ago
  • 🇪🇸Spain eduardo.arana

    Please review it again, this affects 3.0.0-alpha2 version and the warning and deprecated function are not related with https://www.drupal.org/project/openid_connect/issues/3266452 🐛 Adding Generic Oauth2 app and set empty scope then cause system crash RTBC

    Thanks.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    100 pass
  • 🇪🇸Spain eduardo.arana

    Adding the patch with the fixes.

  • 🇲🇾Malaysia elaine.ong

    The patch does not seems to fix the warning. Still getting below:

    Warning: Array to string conversion in Drupal\openid_connect\OpenIDConnect->saveUserinfo() (line 695 of modules/contrib/openid_connect/src/OpenIDConnect.php).
    Drupal\openid_connect\OpenIDConnect->saveUserinfo(Object, Array) (Line: 413)
    Drupal\openid_connect\OpenIDConnect->completeAuthorization(Object, Array) (Line: 296)
    Drupal\openid_connect\Controller\OpenIDConnectRedirectController->authenticate(Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)

  • 🇭🇺Hungary szato

    @elaine.ong

    it's caused by nested role arrays. Related issue: https://www.drupal.org/project/openid_connect_windows_aad/issues/3345637 🐛 Roles unassigned due to array to string conversion Active

  • Status changed to Needs work 5 months ago
  • 🇫🇮Finland heikkiy Oulu

    The patch from #5 does not seem to apply anymore against the latest alpha 3. Marking this as Needs work. I will test if the related issues could also solve the issue.

Production build 0.71.5 2024