Problem/Motivation

The following error occurs when the retrieval of user information fails and $userinfo becomes NULL.

TypeError: Argument 1 passed to mymodule_openid_connect_userinfo_alter() must be of the type array, null given

Steps to reproduce

Proposed resolution

Allow NULL for hook_openid_connect_userinfo_alter():

- function hook_openid_connect_userinfo_alter(array &$userinfo, array $context) {
+ function hook_openid_connect_userinfo_alter(?array &$userinfo, array $context) {

or make sure that $userinfo is array:

    // Drupal\openid_connect\OpenIDConnect::buildContext()
    if ($plugin->usesUserInfo()) {
-      $userinfo = $plugin->retrieveUserInfo($tokens['access_token']);
+      $userinfo = $plugin->retrieveUserInfo($tokens['access_token']) ?: [];
    }

Remaining tasks

n/a

User interface changes

n/a

API changes

n/a

Data model changes

n/a

CommentFileSizeAuthor
#9 3243493-6.patch595 bytespcate
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

hayashi created an issue. See original summary.

mohit.bansal623 made their first commit to this issue’s fork.

mohit.bansal623’s picture

Status: Active » Needs review

Please review the merge request.

mohit.bansal623’s picture

Status: Needs review » Active

PCate made their first commit to this issue’s fork.

pcate’s picture

Version: 2.x-dev » 3.x-dev
Status: Active » Needs review

Made a minor update to the MR to only call the retrieveUserInfo method once, which I think was the cause of the previous test failure. I also changed the branch from 2.x to 3.x since I'm not sure if development will stop on 2.x when Drupal 9 support ends. Either way the change can be merged into both 2.x and 3.x.

Setting the NR.

pcate’s picture

StatusFileSize
new595 bytes

Attached patch of the change as well in case that is more convenient.

pfrilling made their first commit to this issue’s fork.

pfrilling’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Chicago2026

I reviewed and manually tested and all seems correct to me. I added test coverage to validate.

pfrilling’s picture

Status: Reviewed & tested by the community » Fixed

Added to the merge train. Thanks everyone!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • pfrilling committed e44a0e51 on 3.x authored by pcate
    fix: #3243493 Error in hook_openid_connect_userinfo_alter() if $userinfo...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.