Problem/Motivation
When trying to connect via the remote SSO of one of our clients, module openid_connect fails with a 500 fatal error when querying the token:
TypeError: Drupal\openid_connect\OpenIDConnectSession::saveIdToken(): Argument #1 ($token) must be of type string, array given, called in /var/www/public/modules/contrib/openid_connect/src/OpenIDConnect.php on line 429 in Drupal\openid_connect\OpenIDConnectSession->saveIdToken() (line 170 of /var/www/public/modules/contrib/openid_connect/src/OpenIDConnectSession.php).
Steps to reproduce
To reproduce the issue, you need openid_connect to be configured to talk to a remote SSO server that returns the following structure when querying the "Token endpoint" (for instance):
{
"access_token": "XXX",
"token_type": "Bearer",
"refresh_token": "XXX",
"expires_in": 3600,
"id_token":
{
"iss": "https://id.example.com",
"sub": "012345678901",
"aud": "messages",
"exp": 1523632701.51226,
"iat": "2018-04-13T14:18:21Z",
"given_name": "John",
"family_name": "JOHNSON",
"email": "jjohnson@example.com",
"phone_number": "",
"group": "60",
"photo": "https://static.example.com/api/get-photo.aspx?id=012345678901&s=100x100"
}
}
The important part is the "id_token" because some servers do return it as a key/value map instead of an encoded string, as shown above.
Proposed resolution
Currently, the openid_connect module assumes that property "id_token" is necessarily a string when saving it in session via \Drupal\openid_connect\OpenIDConnectSessionInterface::saveAccessToken()
. It is hardcoded as a PHP type.
Although, if I'm not mistaken it's been developed to handle both cases in other parts of the openid_connect module apparently. For instance, function \Drupal\openid_connect\OpenIDConnect::buildContext()
does check whether "id_token" is a string or not before retrieving info from it.
So it feels like we should accept the token to be a string or an array when saving it in session?