Pass $context['is_new'] to openid_connect_post_authorize hook

Created on 7 June 2023, over 2 years ago
Updated 2 October 2025, 7 days ago

Problem/Motivation

See the following code in OpenIDConnect::completeAuthorization

      $account = $this->createUser($context['sub'], $context['userinfo'], $client->id());
...
      // Store the newly created account.
      $this->saveUserinfo($account, $context + ['is_new' => TRUE]);
...
    $this->moduleHandler
      ->invokeAll('openid_connect_post_authorize', [$account, $context]);

The 'is_new' => TRUE is added to the context when calling saveUserinfo, which allows implementations of hook_openid_connect_userinfo_save to know if the account was just created or not.

$account->isNew() would return FALSE, since it has already been saved, so this is very helpful information to have in the context. However, the information is not passed to the hook_openid_connect_post_authorize invocation, as you can see above. I am trying to determine in my hook implementation if the account was just created or not, and I don't see an easy way built-in. It would be nice to have in the $context.

Steps to reproduce

Implement hook_openid_connect_post_authorize, then authenticate for the first time so that an account is created. The post authorize hook will not have a way to know if the account was authenticating for the first time, or the hundredth time.

Proposed resolution

Something like this?

      $account = $this->createUser($context['sub'], $context['userinfo'], $client->id());
      $context += ['is_new' => $is_new];
...
      // Store the newly created account.
      $this->saveUserinfo($account, $context);
...
    $this->moduleHandler
      ->invokeAll('openid_connect_post_authorize', [$account, $context]);

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

3.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024