Skip to content

Instantly share code, notes, and snippets.

@cleverington
Created November 2, 2021 14:39
Show Gist options
  • Save cleverington/740cdcb53699e537917cdba9d9c936ac to your computer and use it in GitHub Desktop.
Save cleverington/740cdcb53699e537917cdba9d9c936ac to your computer and use it in GitHub Desktop.
Temporary patchfile for stable OpenConnect ID - beta5 module.
Index: modules/contrib/openid_connect/openid_connect.module:0
@@ @@
<?php
+use Drupal\Core\File\FileSystemInterface;
/**
* @file
* A pluggable client implementation for the OpenID Connect protocol.
@@ @@
* An array with information about the user.
*/
function openid_connect_save_userinfo(UserInterface $account, array $userinfo) {
- $properties = \Drupal::entityManager()->getFieldDefinitions('user', 'user');
+ $properties = \Drupal::service('entity_field.manager')->getFieldDefinitions('user', 'user');
$properties_skip = _openid_connect_user_properties_to_skip();
foreach ($properties as $property_name => $property) {
if (isset($properties_skip[$property_name])) {
@@ @@
$file = file_save_data(
$data,
'public://user-picture-' . $account->id() . '-' . $basename,
- FILE_EXISTS_RENAME
+ FileSystemInterface::EXISTS_RENAME
);
// Cleanup the old file.
@@ @@
* TRUE if a user exists with the given name, FALSE otherwise.
*/
function openid_connect_username_exists($name) {
- return db_query(
- 'SELECT COUNT(*) FROM {users_field_data} WHERE name = :name',
- [
- ':name' => $name,
- ]
- )->fetchField() > 0;
+ // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
+ // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
+ return \Drupal::database()->query('SELECT COUNT(*) FROM {users_field_data} WHERE name = :name', [
+ ':name' => $name,
+ ])->fetchField() > 0;
}
/**
@@ @@
else {
// Check whether the e-mail address is valid.
if (!\Drupal::service('email.validator')->isValid($userinfo['email'])) {
- drupal_set_message(
- t(
- 'The e-mail address is not valid: @email',
- [
- '@email' => $userinfo['email'],
- ]
- ),
- 'error'
- );
+ \Drupal::messenger()->addError(t(
+ 'The e-mail address is not valid: @email',
+ [
+ '@email' => $userinfo['email'],
+ ]
+ ));
return FALSE;
}
@@ @@
openid_connect_connect_account($account, $client->getPluginId(), $sub);
}
else {
- drupal_set_message(
- t('The e-mail address is already taken: @email',
- [
- '@email' => $userinfo['email'],
- ]
- ),
- 'error'
- );
+ \Drupal::messenger()->addError(t('The e-mail address is already taken: @email',
+ [
+ '@email' => $userinfo['email'],
+ ]
+ ));
return FALSE;
}
}
@@ @@
switch ($register) {
case USER_REGISTER_ADMINISTRATORS_ONLY:
// Deny user registration.
- drupal_set_message(t('Only administrators can register new accounts.'), 'error');
+ \Drupal::messenger()->addError(t('Only administrators can register new accounts.'));
return FALSE;
case USER_REGISTER_VISITORS:
@@ @@
case USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL:
// Create a new account and inform the user of the pending approval.
$account = openid_connect_create_user($sub, $userinfo, $client->getPluginId(), 0);
- drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.'));
+ \Drupal::messenger()->addStatus(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.'));
break;
}
}
@@ @@
}
if ($account && $account->id() !== $user->id()) {
- drupal_set_message(t('Another user is already connected to this @provider account.', $provider_param), 'error');
+ \Drupal::messenger()->addError(t('Another user is already connected to this @provider account.', $provider_param));
return FALSE;
}
Index: modules/contrib/openid_connect/src/Controller/RedirectController.php:148
@@ @@
])) {
// If we have an one of the above errors, that means the user hasn't
// granted the authorization for the claims.
- drupal_set_message(t('Logging in with @provider has been canceled.', $provider_param), 'warning');
+ $this->messenger()->addWarning(t('Logging in with @provider has been canceled.', $provider_param));
}
else {
// Any other error should be logged. E.g. invalid scope.
@@ @@
];
$message = 'Authorization failed: @error. Details: @details';
$this->loggerFactory->get('openid_connect_' . $client_name)->error($message, $variables);
- drupal_set_message(t('Could not authenticate with @provider.', $provider_param), 'error');
+ $this->messenger()->addError(t('Could not authenticate with @provider.', $provider_param));
}
}
else {
@@ @@
$register = \Drupal::config('user.settings')->get('register');
if (!$success && $register !== USER_REGISTER_ADMINISTRATORS_ONLY) {
- drupal_set_message(t('Logging in with @provider could not be completed due to an error.', $provider_param), 'error');
+ $this->messenger()->addError(t('Logging in with @provider could not be completed due to an error.', $provider_param));
}
}
elseif ($parameters['op'] === 'connect' && $parameters['connect_uid'] === $this->currentUser->id()) {
$success = openid_connect_connect_current_user($client, $tokens);
if ($success) {
- drupal_set_message($this->t('Account successfully connected with @provider.', $provider_param));
+ $this->messenger()->addStatus($this->t('Account successfully connected with @provider.', $provider_param));
}
else {
- drupal_set_message($this->t('Connecting with @provider could not be completed due to an error.', $provider_param), 'error');
+ $this->messenger()->addError($this->t('Connecting with @provider could not be completed due to an error.', $provider_param));
}
}
}
Index: modules/contrib/openid_connect/src/Form/AccountsForm.php:178
@@ @@
if ($op === 'disconnect') {
$this->authmap->deleteAssociation($form_state->get('account')->id(), $client_name);
$client = $this->pluginManager->getDefinition($client_name);
- drupal_set_message(t('Account successfully disconnected from @client.', ['@client' => $client['label']]));
+ $this->messenger()->addStatus(t('Account successfully disconnected from @client.', ['@client' => $client['label']]));
return;
}
if ($this->currentUser->id() !== $form_state->get('account')->id()) {
- drupal_set_message($this->t("You cannot connect another user's account."), 'error');
+ $this->messenger()->addError($this->t("You cannot connect another user's account."));
return;
}
Index: modules/contrib/openid_connect/src/Plugin/OpenIDConnectClientBase.php:253
@@ @@
'access_token' => isset($response_data['access_token']) ? $response_data['access_token'] : NULL,
];
if (array_key_exists('expires_in', $response_data)) {
- $tokens['expire'] = REQUEST_TIME + $response_data['expires_in'];
+ $tokens['expire'] = \Drupal::time()->getRequestTime() + $response_data['expires_in'];
}
if (array_key_exists('refresh_token', $response_data)) {
$tokens['refresh_token'] = $response_data['refresh_token'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment