Commit 9c2ba1b8 authored by Joao Ventura's avatar Joao Ventura
Browse files

Coding standards

parent d9d18c7c
......@@ -5,6 +5,8 @@
* Documentation for OpenID Connect module APIs.
*/
/* @noinspection PhpUnused */
use Drupal\user\UserInterface;
/**
......@@ -267,8 +269,9 @@ function hook_openid_connect_userinfo_save(UserInterface $account, array $contex
* An array of of properties to skip.
*
* @ingroup openid_connect_api
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use hook_openid_connect_user_properties_ignore_alter() instead.
* @see https://www.drupal.org/project/openid_connect/issues/2921095
*/
function hook_openid_connect_user_properties_to_skip_alter(array &$properties_to_skip) {
}
......@@ -5,8 +5,8 @@
* Hook implementations of the OpenID Connect module.
*/
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
/** @noinspection PhpUnused */
/* @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
/* @noinspection PhpUnused */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -18,10 +18,10 @@ use Drupal\user\UserInterface;
* Implements hook_help().
*/
function openid_connect_help($route_name, RouteMatchInterface $route_match) {
$output = '';
switch ($route_name) {
// Main module help for the keycloak module.
case 'help.page.openid_connect':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('A pluggable client implementation for the OpenID Connect protocol. You can enable available OpenID Connect clients within the <a href=":settings">OpenID Connect settings</a> page. For more information, see the <a href=":documentation">online documentation for the OpenID Connect module</a>.', [
':settings' => Url::fromRoute('openid_connect.admin_settings')->toString(),
......@@ -38,9 +38,8 @@ function openid_connect_help($route_name, RouteMatchInterface $route_match) {
$output .= '<dt>' . t('Synchronize user properties/fields with OpenID Connect claims') . '</dt>';
$output .= '<dd>' . t("During login and user registration user attributes can optionally be synchronized with the OpenID Connect claims mapping.") . '</dd>';
$output .= '</dl>';
return $output;
}
return $output;
}
/**
......@@ -179,12 +178,13 @@ function openid_connect_form_user_login_form_alter(&$form, FormStateInterface $f
* @param array $userinfo
* An array with information about the user.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnect::saveUserinfo() or
* \Drupal::service('openid_connect.openid_connect')->saveUserinfo() instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_save_userinfo(UserInterface $account, array $userinfo) {
@trigger_error('openid_connect_save_userinfo() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_save_userinfo() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnect::saveUserinfo() or \Drupal::service('openid_connect.openid_connect')->saveUserinfo() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
\Drupal::service('openid_connect.openid_connect')->saveUserinfo($account, $userinfo);
}
......@@ -194,24 +194,26 @@ function openid_connect_save_userinfo(UserInterface $account, array $userinfo) {
* @param \Drupal\user\UserInterface $account
* The user account.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnect::loginUser() or
* user_login_finalize() instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_login_user(UserInterface $account) {
@trigger_error('openid_connect_login_user() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_login_user() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnect::loginUser() or user_login_finalize() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
user_login_finalize($account);
}
/**
* Save the current path in the session, for redirecting after authorization.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnectSession::saveDestination() or
* \Drupal::service('openid_connect.session')->saveDestination() instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_save_destination() {
@trigger_error('openid_connect_save_destination() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_save_destination() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnectSession::saveDestination() or \Drupal::service('openid_connect.session')->saveDestination() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
\Drupal::service('openid_connect.session')->saveDestination();
}
......@@ -230,12 +232,13 @@ function openid_connect_save_destination() {
* @return object|false
* The user object or FALSE on failure.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnect::createUser() or
* \Drupal::service('openid_connect.openid_connect')->createUser() instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_create_user($sub, array $userinfo, $client_name, $status = 1) {
@trigger_error('openid_connect_create_user() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_create_user() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnect::createUser() or \Drupal::service('openid_connect.openid_connect')->createUser() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
return \Drupal::service('openid_connect.openid_connect')->createUser($sub, $userinfo, $client_name, $status);
}
......@@ -252,14 +255,15 @@ function openid_connect_create_user($sub, array $userinfo, $client_name, $status
* @return string
* A unique username.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* No replacement is intended. The new method
* Drupal\openid_connect\OpenIDConnect::generateUsername() or
* \Drupal::service('openid_connect.openid_connect')->generateUsername()
* will be set protected for the OpenID Connect service.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_generate_username($sub, array $userinfo, $client_name) {
@trigger_error('openid_connect_generate_username() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_generate_username() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. No replacement is intended. The new method Drupal\openid_connect\OpenIDConnect::generateUsername() or \Drupal::service('openid_connect.openid_connect')->generateUsername() will be set protected for the OpenID Connect service. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
return \Drupal::service('openid_connect.openid_connect')->generateUsername($sub, $userinfo, $client_name);
}
......@@ -272,14 +276,15 @@ function openid_connect_generate_username($sub, array $userinfo, $client_name) {
* @return bool
* TRUE if a user exists with the given name, FALSE otherwise.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* No replacement is intended. The new method
* Drupal\openid_connect\OpenIDConnect::usernameExists() or
* \Drupal::service('openid_connect.openid_connect')->usernameExists()
* will be set protected for the OpenID Connect service.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_username_exists($name) {
@trigger_error('openid_connect_username_exists() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_username_exists() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. No replacement is intended. The new method Drupal\openid_connect\OpenIDConnect::usernameExists() or \Drupal::service('openid_connect.openid_connect')->usernameExists() will be set protected for the OpenID Connect service. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
return \Drupal::service('openid_connect.openid_connect')->usernameExists($name);
}
......@@ -292,13 +297,14 @@ function openid_connect_username_exists($name) {
* @return bool
* TRUE if access is granted, FALSE otherwise.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnect::hasSetPasswordAccess() or
* \Drupal::service('openid_connect.openid_connect')->hasSetPasswordAccess()
* instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_set_password_access($account) {
@trigger_error('openid_connect_set_password_access() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_set_password_access() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnect::hasSetPasswordAccess() or \Drupal::service('openid_connect.openid_connect')->hasSetPasswordAccess() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
return \Drupal::service('openid_connect.openid_connect')->hasSetPasswordAccess($account);
}
......@@ -312,12 +318,13 @@ function openid_connect_set_password_access($account) {
* @param string $sub
* The 'sub' property identifying the external account.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnectAuthmap::createAssociation() or
* \Drupal::service('openid_connect.authmap')->createAssociation() instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_connect_account($account, $client_name, $sub) {
@trigger_error('openid_connect_connect_account() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_connect_account() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnectAuthmap::createAssociation() or \Drupal::service('openid_connect.authmap')->createAssociation() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
\Drupal::service('openid_connect.authmap')->createAssociation($account, $client_name, $sub);
}
......@@ -329,12 +336,13 @@ function openid_connect_connect_account($account, $client_name, $sub) {
* @param string $client_name
* The client machine name.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnectAuthmap::deleteAssociation() or
* \Drupal::service('openid_connect.authmap')->deleteAssociation() instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_disconnect_account($account, $client_name) {
@trigger_error('openid_connect_disconnect_account() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_disconnect_account() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnectAuthmap::deleteAssociation() or \Drupal::service('openid_connect.authmap')->deleteAssociation() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
\Drupal::service('openid_connect.authmap')->deleteAssociation($account->id(), $client_name);
}
......@@ -354,12 +362,13 @@ function openid_connect_disconnect_account($account, $client_name) {
* @return string|false
* The sub, or FALSE if there was an error.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnect::extractSub() or
* \Drupal::service('openid_connect.openid_connect')->extractSub() instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_extract_sub(array $user_data, array $userinfo) {
@trigger_error('openid_connect_extract_sub() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_extract_sub() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnect::extractSub() or \Drupal::service('openid_connect.openid_connect')->extractSub() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
return \Drupal::service('openid_connect.openid_connect')->extractSub($user_data, $userinfo);
}
......@@ -376,13 +385,14 @@ function openid_connect_extract_sub(array $user_data, array $userinfo) {
* @return bool
* TRUE on success, FALSE on failure.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnect::completeAuthorization() or
* \Drupal::service('openid_connect.openid_connect')->completeAuthorization()
* instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_complete_authorization($client, array $tokens, &$destination) {
@trigger_error('openid_connect_complete_authorization() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_complete_authorization() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnect::completeAuthorization() or \Drupal::service('openid_connect.openid_connect')->completeAuthorization() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
return \Drupal::service('openid_connect.openid_connect')->completeAuthorization($client, $tokens, $destination);
}
......@@ -397,12 +407,13 @@ function openid_connect_complete_authorization($client, array $tokens, &$destina
* @return bool
* TRUE on success, FALSE on failure.
*
* @deprecated in openid_connect 8.x-1.x-beta6, will be removed in 8.x-1.x-rc1.
* @deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1.
* Use Drupal\openid_connect\OpenIDConnect::connectCurrentUser() or
* \Drupal::service('openid_connect.openid_connect')->connectCurrentUser()
* instead.
* @see https://www.drupal.org/project/openid_connect/issues/2961938
*/
function openid_connect_connect_current_user($client, array $tokens) {
@trigger_error('openid_connect_connect_current_user() is deprecated and will be removed in 8.x-1.x-rc1.', E_USER_DEPRECATED);
@trigger_error("openid_connect_connect_current_user() is deprecated in openid_connect:8.x-1.0-beta6 and is removed from openid_connect:8.x-1.0-rc1. Use Drupal\openid_connect\OpenIDConnect::connectCurrentUser() or \Drupal::service('openid_connect.openid_connect')->connectCurrentUser() instead. See https://www.drupal.org/project/openid_connect/issues/2961938", E_USER_DEPRECATED);
return \Drupal::service('openid_connect.openid_connect')->connectCurrentUser($client, $tokens);
}
......@@ -179,18 +179,18 @@ class OpenIDConnectSettingsForm extends ConfigFormBase implements ContainerInjec
'#default_value' => $settings->get('connect_existing_users'),
];
$form['user_login_display'] = array(
$form['user_login_display'] = [
'#type' => 'radios',
'#title' => $this->t('OpenID buttons display in user login form'),
'#options' => array(
'#options' => [
'hidden' => $this->t('Hidden'),
'above' => $this->t('Above'),
'below' => $this->t('Below'),
'replace' => $this->t('Replace'),
),
],
'#description' => $this->t("Modify the user login form to show the the OpenID login buttons. If the 'Replace' option is selected, only the OpenID buttons will be displayed. In this case, pass the 'showcore' URL parameter to return to a password-based login form."),
'#default_value' => $settings->get('user_login_display'),
);
];
$form['userinfo_mappings'] = [
'#title' => $this->t('User claims mapping'),
......@@ -315,6 +315,8 @@ class OpenIDConnectSettingsForm extends ConfigFormBase implements ContainerInjec
* @return \Drupal\openid_connect\Plugin\OpenIDConnectClientInterface[]
* Associative array of OpenID Connect client plugins with client IDs
* as keys and the corresponding initialized client plugins as values.
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
protected function getClients() {
if (!isset(self::$clients)) {
......
......@@ -32,6 +32,7 @@ use stdClass;
/**
* Class OpenIDConnectTest.
*
* @coversDefaultClass \Drupal\openid_connect\OpenIDConnect
* @group openid_connect
*/
......@@ -575,12 +576,6 @@ class OpenIDConnectTest extends UnitTestCase {
$client = $this
->createMock(OpenIDConnectClientInterface::class);
$moduleHandlerCount = 1;
if ($preAuthorize) {
$moduleHandlerCount = 3;
}
if ($authenticated) {
$this->expectException('RuntimeException');
}
......@@ -656,14 +651,6 @@ class OpenIDConnectTest extends UnitTestCase {
$account->method('id')->willReturn(1234);
$account->method('isNew')->willReturn(FALSE);
$context = [
'tokens' => $tokens,
'plugin_id' => $clientPluginId,
'user_data' => $userData,
'userinfo' => $userInfo,
'sub' => $userInfo['sub'],
];
$this->authMap->expects($this->once())
->method('userLoadBySub')
->willReturn($account);
......@@ -711,13 +698,6 @@ class OpenIDConnectTest extends UnitTestCase {
}
else {
$account = FALSE;
$context = [
'tokens' => $tokens,
'plugin_id' => $clientPluginId,
'user_data' => $userData,
'userinfo' => $userInfo,
'sub' => $userInfo['sub'],
];
$this->authMap->expects($this->once())
->method('userLoadBySub')
......@@ -1141,7 +1121,6 @@ class OpenIDConnectTest extends UnitTestCase {
array $userInfo,
bool $expectedResult
): void {
$exceptionExpected = FALSE;
$pluginId = $this->randomMachineName();
$client = $this
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment