Error: getCredentials(): Return value must be of type array, null returned

Created on 28 June 2023, over 1 year ago
Updated 6 July 2023, over 1 year ago

Problem/Motivation

I have enabled an oauth2 client, configured it, and exported that configuration. When I import that configuration on another instance of the site, I get this error when attempting to edit the oauth2 client:

The website encountered an unexpected error. Please try again later.
TypeError: Drupal\oauth2_client\Service\CredentialProvider::getCredentials(): Return value must be of type array, null returned in Drupal\oauth2_client\Service\CredentialProvider->getCredentials() (line 90 of modules/contrib/oauth2_client/src/Service/CredentialProvider.php).
Drupal\oauth2_client\Service\CredentialProvider->getCredentials() (Line: 92)
Drupal\oauth2_client\Form\Oauth2ClientForm->form() (Line: 106)
Drupal\Core\Entity\EntityForm->buildForm()
...

For what it's worth, I'm not using the Key module, just the built-in Drupal state for client credentials.

This seems to be the result of the Drupal state not being present and yet oauth2_client\Service\CredentialProvider::getCredentials() is annotated as returning an array. With no state to return, it actually returns null.

Steps to reproduce

  1. Enable an oauth2 client
  2. Export the site config
  3. Import the site config on another database instance

Proposed resolution

Either update oauth2_client\Service\CredentialProvider::getCredentials() to return array | null, or update it to check that $credentials is an array before returning it.

I've chosen to check that $credentials is an array before returning it.

Remaining tasks

Review patch.

User interface changes

N/A

API changes

N/A

Data model changes

πŸ› Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States pianomansam

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

Comments & Activities

Production build 0.71.5 2024