function hook_openid_connect_userinfo_alter in OpenID Connect / OAuth client 2.x
Same name and namespace in other branches
- 8 openid_connect.api.php \hook_openid_connect_userinfo_alter()
Alter the user information provided by the identity provider.
This hook is called after the user information has been fetched from the identity provider's userinfo endpoint, and before authorization or connecting a user takes place.
Popular use cases for this hook are providing additional user information, or 'translating' information from a format used by the identity provider to a format that can be used by the OpenID Connect claim mapping.
Parameters
array $userinfo: Array of returned user information from the identity provider.
array $context: An associative array with context information:
- tokens: An array of tokens.
- user_data: An array of user and session information from the ID token.
- plugin_id: The plugin identifier.
1 invocation of hook_openid_connect_userinfo_alter()
- OpenIDConnect::buildContext in src/
OpenIDConnect.php - Fill the context array.
File
- ./
openid_connect.api.php, line 112 - Documentation for OpenID Connect module APIs.
Code
function hook_openid_connect_userinfo_alter(array &$userinfo, array $context) {
// Add some custom information.
if ($context['plugin_id'] == 'generic') {
$userinfo['my_info'] = [
'full_name' => $userinfo['first_name'] . ' ' . $userinfo['last_name'],
'remarks' => 'Information provided by generic client plugin.',
];
}
}