Skip to content
Snippets Groups Projects
Commit e64ba8e7 authored by Michael Lee's avatar Michael Lee
Browse files

Upgrading drupal/externalauth (1.4.0 => 2.0.3)

parent 6a4e1a3f
No related branches found
No related tags found
No related merge requests found
Showing
with 910 additions and 106 deletions
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "29697f1f20312fa7ad5e6e7db1e7e4e5",
"content-hash": "e06a98cd11adca9e22ae3d9050043519",
"packages": [
{
"name": "alchemy/zippy",
......@@ -4000,26 +4000,26 @@
},
{
"name": "drupal/externalauth",
"version": "1.4.0",
"version": "2.0.3",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/externalauth.git",
"reference": "8.x-1.4"
"reference": "2.0.3"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/externalauth-8.x-1.4.zip",
"reference": "8.x-1.4",
"shasum": "caea7d2d5a890adad9e6b5beaa2cf139727266d6"
"url": "https://ftp.drupal.org/files/projects/externalauth-2.0.3.zip",
"reference": "2.0.3",
"shasum": "dae49e3df8739538d7b9371ab7fb5005b8d953fd"
},
"require": {
"drupal/core": "^8 || ^9"
"drupal/core": "^9 || ^10"
},
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-1.4",
"datestamp": "1624457496",
"version": "2.0.3",
"datestamp": "1668777505",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -4032,8 +4032,9 @@
],
"authors": [
{
"name": "rgristroph",
"homepage": "https://www.drupal.org/user/516442"
"name": "Sven Decabooter",
"homepage": "https://www.drupal.org/u/svendecabooter",
"role": "Maintainer"
},
{
"name": "snufkin",
......@@ -4045,9 +4046,10 @@
}
],
"description": "Helper module to authenticate users using an external site / service and storing identification details",
"homepage": "https://www.drupal.org/project/externalauth",
"homepage": "https://drupal.org/project/externalauth",
"support": {
"source": "https://git.drupalcode.org/project/externalauth"
"source": "https://git.drupalcode.org/project/externalauth",
"issues": "https://www.drupal.org/project/issues/externalauth"
}
},
{
......
......@@ -4139,27 +4139,27 @@
},
{
"name": "drupal/externalauth",
"version": "1.4.0",
"version_normalized": "1.4.0.0",
"version": "2.0.3",
"version_normalized": "2.0.3.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/externalauth.git",
"reference": "8.x-1.4"
"reference": "2.0.3"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/externalauth-8.x-1.4.zip",
"reference": "8.x-1.4",
"shasum": "caea7d2d5a890adad9e6b5beaa2cf139727266d6"
"url": "https://ftp.drupal.org/files/projects/externalauth-2.0.3.zip",
"reference": "2.0.3",
"shasum": "dae49e3df8739538d7b9371ab7fb5005b8d953fd"
},
"require": {
"drupal/core": "^8 || ^9"
"drupal/core": "^9 || ^10"
},
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-1.4",
"datestamp": "1624457496",
"version": "2.0.3",
"datestamp": "1668777505",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -4173,8 +4173,9 @@
],
"authors": [
{
"name": "rgristroph",
"homepage": "https://www.drupal.org/user/516442"
"name": "Sven Decabooter",
"homepage": "https://www.drupal.org/u/svendecabooter",
"role": "Maintainer"
},
{
"name": "snufkin",
......@@ -4186,9 +4187,10 @@
}
],
"description": "Helper module to authenticate users using an external site / service and storing identification details",
"homepage": "https://www.drupal.org/project/externalauth",
"homepage": "https://drupal.org/project/externalauth",
"support": {
"source": "https://git.drupalcode.org/project/externalauth"
"source": "https://git.drupalcode.org/project/externalauth",
"issues": "https://www.drupal.org/project/issues/externalauth"
},
"install-path": "../../web/modules/externalauth"
},
......
......@@ -3,7 +3,7 @@
'name' => 'osu-asc-webservices/d8-upstream',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'eedf8cf2fe6599bb32dea9e590be4b8a93b63825',
'reference' => '6a4e1a3f118a4eaf9856bc54963aeb2acdbc6893',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
......@@ -734,9 +734,9 @@
'dev_requirement' => false,
),
'drupal/externalauth' => array(
'pretty_version' => '1.4.0',
'version' => '1.4.0.0',
'reference' => '8.x-1.4',
'pretty_version' => '2.0.3',
'version' => '2.0.3.0',
'reference' => '2.0.3',
'type' => 'drupal-module',
'install_path' => __DIR__ . '/../../web/modules/externalauth',
'aliases' => array(),
......@@ -1549,7 +1549,7 @@
'osu-asc-webservices/d8-upstream' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'eedf8cf2fe6599bb32dea9e590be4b8a93b63825',
'reference' => '6a4e1a3f118a4eaf9856bc54963aeb2acdbc6893',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
......
{
"name": "drupal/externalauth",
"type": "drupal-module",
"description": "Helper module to authenticate users using an external site / service and storing identification details",
"homepage": "https://drupal.org/project/externalauth",
"license": "GPL-2.0-or-later",
"minimum-stability": "dev",
"require": {
"drupal/core": "^9 || ^10"
},
"authors": [
{
"name": "Sven Decabooter",
"homepage": "https://www.drupal.org/u/svendecabooter",
"role": "Maintainer"
}
],
"support": {
"issues": "https://www.drupal.org/project/issues/externalauth",
"source": "https://git.drupalcode.org/project/externalauth"
}
}
langcode: en
status: true
dependencies:
module:
- externalauth
- user
id: authmap
label: 'External authentication links'
module: views
description: ''
tag: ''
base_table: authmap
base_field: ''
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'view authmap'
cache:
type: none
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: mini
options:
items_per_page: 50
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ‹‹
next: ››
style:
type: table
options:
grouping: { }
row_class: ''
default_row_class: true
override: true
sticky: false
caption: ''
summary: ''
description: ''
columns:
authname: authname
uid: uid
name: name
delete: delete
info:
authname:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
uid:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
name:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
delete:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
default: authname
empty_table: false
row:
type: fields
fields:
provider_field:
id: provider_field
table: authmap
field: provider_field
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: true
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
plugin_id: standard
authname:
id: authname
table: authmap
field: authname
relationship: none
group_type: group
admin_label: ''
label: 'Authentication Name'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
plugin_id: standard
uid:
id: uid
table: authmap
field: uid
relationship: none
group_type: group
admin_label: ''
label: 'Drupal User ID'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
set_precision: false
precision: 0
decimal: .
separator: ''
format_plural: false
format_plural_string: !!binary MQNAY291bnQ=
prefix: ''
suffix: ''
plugin_id: numeric
name:
id: name
table: users_field_data
field: name
relationship: uid
group_type: group
admin_label: ''
label: 'Drupal User Name'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: user_name
settings:
link_to_entity: true
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: user
entity_field: name
plugin_id: field
delete_link:
id: delete_link
table: authmap
field: delete_link
relationship: none
group_type: group
admin_label: ''
label: delete
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
text: delete
output_url_as_text: false
absolute: false
plugin_id: authmap_link_delete
filters:
authname:
id: authname
table: authmap
field: authname
relationship: none
group_type: group
admin_label: ''
operator: starts
value: ''
group: 1
exposed: true
expose:
operator_id: authname_op
label: 'Authentication name'
description: ''
use_operator: false
operator: authname_op
operator_limit_selection: false
operator_list: { }
identifier: authname
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
role3: '0'
role4: '0'
placeholder: ''
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
uid:
id: uid
table: users_field_data
field: uid
relationship: uid
group_type: group
admin_label: ''
operator: in
value: { }
group: 1
exposed: true
expose:
operator_id: uid_op
label: 'Drupal user'
description: ''
use_operator: false
operator: uid_op
operator_limit_selection: false
operator_list: { }
identifier: uid
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
role3: '0'
role4: '0'
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: user
entity_field: uid
plugin_id: user_name
sorts: { }
title: 'External authentication links'
header: { }
footer: { }
empty:
area_text_custom:
id: area_text_custom
table: views
field: area_text_custom
relationship: none
group_type: group
admin_label: ''
empty: true
tokenize: false
content: 'No links (from Authentication name to Drupal user) found.'
plugin_id: text_custom
relationships:
uid:
id: uid
table: authmap
field: uid
relationship: none
group_type: group
admin_label: 'Linked Drupal user'
required: false
plugin_id: standard
arguments:
provider_field:
id: provider_field
table: authmap
field: provider_field
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: true
title: 'Links for {{ arguments.provider_field }}'
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
items_per_page: 25
count: false
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
glossary: false
limit: 0
case: none
path_case: none
transform_dash: false
break_phrase: false
plugin_id: string
display_extenders: { }
show_admin_links: false
cache_metadata:
max-age: -1
contexts:
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
tags: { }
page:
display_plugin: page
id: page
display_title: Page
position: 1
display_options:
display_extenders: { }
path: admin/people/authmap
menu:
type: tab
title: External
description: ''
expanded: false
parent: entity.user.collection
weight: 20
context: '0'
menu_name: admin
cache_metadata:
max-age: -1
contexts:
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
tags: { }
views.field.authmap_link_delete:
type: views.field.entity_link
name: External Authentication
type: module
description: Helper module to authenticate users using an external site / service and storing identification details
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
package: 'User authentication'
# Information added by Drupal.org packaging script on 2021-06-23
version: '8.x-1.4'
# Information added by Drupal.org packaging script on 2022-11-18
version: '2.0.3'
project: 'externalauth'
datestamp: 1624457461
datestamp: 1668777508
view authmap:
title: 'View external authentication data'
delete authmap:
title: 'Delete external authentication data'
<?php
/**
* @file
* Post update functions for the externalauth module.
*/
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\views\Entity\View;
/**
* Imports new view for authmap entries.
*/
function externalauth_post_update_add_view_authmap() {
if (\Drupal::moduleHandler()->moduleExists('views') && !View::load('authmap')) {
$module_path = \Drupal::moduleHandler()->getModule('externalauth')->getPath();
$file_storage = new FileStorage($module_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY);
$view = \Drupal::entityTypeManager()->getStorage('view')->create($file_storage->read('views.view.authmap'));
$view->save();
}
}
externalauth.authmap_delete_form:
path: '/admin/people/authmap/{provider}/{uid}/delete'
defaults:
_form: '\Drupal\externalauth\Form\AuthmapDeleteForm'
_title: 'Delete authmap entry'
requirements:
_permission: 'delete authmap'
......@@ -55,6 +55,32 @@ function externalauth_views_data() {
'id' => 'string',
],
],
'uid' => [
'title' => t('Drupal User ID'),
'help' => t('The user linked to the authname.'),
'relationship' => [
'base' => 'users_field_data',
'base field' => 'uid',
'id' => 'standard',
'label' => t('Linked Drupal user'),
],
'field' => [
'id' => 'numeric',
],
'filter' => [
'id' => 'numeric',
],
'sort' => [
'id' => 'standard',
],
],
'delete_link' => [
'title' => t('Link to delete @label entry', ['@label' => 'authmap']),
'help' => t('Provide a link to delete the @label entry.', ['@label' => 'authmap']),
'field' => [
'id' => 'authmap_link_delete',
],
],
];
return $data;
......
......@@ -6,9 +6,7 @@
use Drupal\user\UserInterface;
/**
* Class Authmap.
*
* @package Drupal\externalauth
* Service for managing authmap database records.
*/
class Authmap implements AuthmapInterface {
......@@ -32,7 +30,7 @@ public function __construct(Connection $connection) {
/**
* {@inheritdoc}
*/
public function save(UserInterface $account, $provider, $authname, $data = NULL) {
public function save(UserInterface $account, string $provider, string $authname, $data = NULL) {
if (!is_scalar($data)) {
$data = serialize($data);
}
......@@ -56,7 +54,7 @@ public function save(UserInterface $account, $provider, $authname, $data = NULL)
/**
* {@inheritdoc}
*/
public function get($uid, $provider) {
public function get(int $uid, string $provider) {
$authname = $this->connection->select('authmap', 'am')
->fields('am', ['authname'])
->condition('uid', $uid)
......@@ -73,7 +71,7 @@ public function get($uid, $provider) {
/**
* {@inheritdoc}
*/
public function getAuthData($uid, $provider) {
public function getAuthData(int $uid, string $provider) {
$data = $this->connection->select('authmap', 'am')
->fields('am', ['authname', 'data'])
->condition('uid', $uid)
......@@ -87,7 +85,7 @@ public function getAuthData($uid, $provider) {
/**
* {@inheritdoc}
*/
public function getAll($uid) {
public function getAll($uid): array {
$query = $this->connection->select('authmap', 'am')
->fields('am', ['provider', 'authname'])
->condition('uid', $uid)
......@@ -105,7 +103,7 @@ public function getAll($uid) {
/**
* {@inheritdoc}
*/
public function getUid($authname, $provider) {
public function getUid(string $authname, string $provider) {
$authname = $this->connection->select('authmap', 'am')
->fields('am', ['uid'])
->condition('authname', $authname)
......@@ -122,7 +120,7 @@ public function getUid($authname, $provider) {
/**
* {@inheritdoc}
*/
public function delete($uid, $provider = NULL) {
public function delete(int $uid, string $provider = NULL) {
$query = $this->connection->delete('authmap')
->condition('uid', $uid);
......@@ -136,7 +134,7 @@ public function delete($uid, $provider = NULL) {
/**
* {@inheritdoc}
*/
public function deleteProvider($provider) {
public function deleteProvider(string $provider) {
$this->connection->delete('authmap')
->condition('provider', $provider)
->execute();
......
......@@ -5,9 +5,7 @@
use Drupal\user\UserInterface;
/**
* Interface AuthmapInterface.
*
* @package Drupal\externalauth
* Interface for Authmap service.
*/
interface AuthmapInterface {
......@@ -24,7 +22,7 @@ interface AuthmapInterface {
* @param mixed $data
* Optional extra (serialized) data to store with the authname.
*/
public function save(UserInterface $account, $provider, $authname, $data = NULL);
public function save(UserInterface $account, string $provider, string $authname, $data = NULL);
/**
* Get the external authname for a given user ID.
......@@ -37,7 +35,7 @@ public function save(UserInterface $account, $provider, $authname, $data = NULL)
* @return string|bool
* The external authname / ID, or FALSE.
*/
public function get($uid, $provider);
public function get(int $uid, string $provider);
/**
* Get the external authname & extra data for a given user ID.
......@@ -47,10 +45,10 @@ public function get($uid, $provider);
* @param string $provider
* The name of the service providing external authentication.
*
* @return array
* @return array|bool
* An array with authname & data values.
*/
public function getAuthData($uid, $provider);
public function getAuthData(int $uid, string $provider);
/**
* Get all external authnames for a given user ID.
......@@ -62,7 +60,7 @@ public function getAuthData($uid, $provider);
* An array of external authnames / IDs for the given user ID, keyed by
* provider name.
*/
public function getAll($uid);
public function getAll(int $uid): array;
/**
* Get a Drupal user ID based on an authname.
......@@ -77,7 +75,7 @@ public function getAll($uid);
* @return int|bool
* The Drupal user ID or FALSE.
*/
public function getUid($authname, $provider);
public function getUid(string $authname, string $provider);
/**
* Delete authmap entries for a given Drupal user ID.
......@@ -86,10 +84,10 @@ public function getUid($authname, $provider);
*
* @param int $uid
* The Drupal user ID.
* @param string $provider
* @param string|null $provider
* (optional) The name of the service providing external authentication.
*/
public function delete($uid, $provider = NULL);
public function delete(int $uid, string $provider = NULL);
/**
* Delete all authmap entries for a given provider.
......@@ -97,6 +95,6 @@ public function delete($uid, $provider = NULL);
* @param string $provider
* The name of the service providing external authentication.
*/
public function deleteProvider($provider);
public function deleteProvider(string $provider);
}
......@@ -2,7 +2,7 @@
namespace Drupal\externalauth\Event;
use Symfony\Component\EventDispatcher\Event;
use Drupal\Component\EventDispatcher\Event;
/**
* Allow event listeners to alter the authmap data that will get stored.
......@@ -65,7 +65,7 @@ public function __construct($provider, $authname, $username, $data = NULL) {
* @return string
* The name of the service providing external authentication.
*/
public function getProvider() {
public function getProvider(): string {
return $this->provider;
}
......@@ -76,7 +76,7 @@ public function getProvider() {
* The unique, external authentication name provided by authentication
* provider.
*/
public function getAuthname() {
public function getAuthname(): string {
return $this->authname;
}
......@@ -97,7 +97,7 @@ public function setAuthname($authname) {
* @return string
* The username to generate when registering this user.
*/
public function getUsername() {
public function getUsername(): string {
return $this->username;
}
......
......@@ -3,7 +3,7 @@
namespace Drupal\externalauth\Event;
use Drupal\user\UserInterface;
use Symfony\Component\EventDispatcher\Event;
use Drupal\Component\EventDispatcher\Event;
/**
* Notify event listeners about an externalauth user login.
......@@ -56,7 +56,7 @@ public function __construct(UserInterface $account, $provider, $authname) {
* @return \Drupal\user\UserInterface
* The Drupal user account.
*/
public function getAccount() {
public function getAccount(): UserInterface {
return $this->account;
}
......@@ -66,7 +66,7 @@ public function getAccount() {
* @return string
* The name of the service providing external authentication.
*/
public function getProvider() {
public function getProvider(): string {
return $this->provider;
}
......@@ -77,7 +77,7 @@ public function getProvider() {
* The unique, external authentication name provided by authentication
* provider.
*/
public function getAuthname() {
public function getAuthname(): string {
return $this->authname;
}
......
......@@ -3,7 +3,7 @@
namespace Drupal\externalauth\Event;
use Drupal\user\UserInterface;
use Symfony\Component\EventDispatcher\Event;
use Drupal\Component\EventDispatcher\Event;
/**
* Notify event listeners about an externalauth user registration.
......@@ -66,7 +66,7 @@ public function __construct(UserInterface $account, $provider, $authname, $data
* @return \Drupal\user\UserInterface
* The Drupal user account.
*/
public function getAccount() {
public function getAccount(): UserInterface {
return $this->account;
}
......@@ -76,7 +76,7 @@ public function getAccount() {
* @return string
* The name of the service providing external authentication.
*/
public function getProvider() {
public function getProvider(): string {
return $this->provider;
}
......@@ -87,7 +87,7 @@ public function getProvider() {
* The unique, external authentication name provided by authentication
* provider.
*/
public function getAuthname() {
public function getAuthname(): string {
return $this->authname;
}
......
......@@ -2,7 +2,6 @@
namespace Drupal\externalauth;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
......@@ -14,19 +13,10 @@
use Drupal\externalauth\Exception\ExternalAuthRegisterException;
/**
* Class ExternalAuth.
*
* @package Drupal\externalauth
* Service to handle external authentication logic.
*/
class ExternalAuth implements ExternalAuthInterface {
use DeprecatedServicePropertyTrait;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The entity type manager service.
*
......@@ -77,7 +67,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Aut
/**
* {@inheritdoc}
*/
public function load($authname, $provider) {
public function load(string $authname, string $provider) {
if ($uid = $this->authmap->getUid($authname, $provider)) {
return $this->entityTypeManager->getStorage('user')->load($uid);
}
......@@ -87,7 +77,7 @@ public function load($authname, $provider) {
/**
* {@inheritdoc}
*/
public function login($authname, $provider) {
public function login(string $authname, string $provider) {
$account = $this->load($authname, $provider);
if ($account) {
return $this->userLoginFinalize($account, $authname, $provider);
......@@ -98,7 +88,7 @@ public function login($authname, $provider) {
/**
* {@inheritdoc}
*/
public function register($authname, $provider, array $account_data = [], $authmap_data = NULL) {
public function register(string $authname, string $provider, array $account_data = [], $authmap_data = NULL) {
if (!empty($account_data['name'])) {
$username = $account_data['name'];
unset($account_data['name']);
......@@ -107,7 +97,7 @@ public function register($authname, $provider, array $account_data = [], $authma
$username = $provider . '_' . $authname;
}
$authmap_event = $this->eventDispatcher->dispatch(ExternalAuthEvents::AUTHMAP_ALTER, new ExternalAuthAuthmapAlterEvent($provider, $authname, $username, $authmap_data));
$authmap_event = $this->eventDispatcher->dispatch(new ExternalAuthAuthmapAlterEvent($provider, $authname, $username, $authmap_data), ExternalAuthEvents::AUTHMAP_ALTER);
$entity_storage = $this->entityTypeManager->getStorage('user');
$account_search = $entity_storage->loadByProperties(['name' => $authmap_event->getUsername()]);
......@@ -130,7 +120,7 @@ public function register($authname, $provider, array $account_data = [], $authma
$account->enforceIsNew();
$account->save();
$this->authmap->save($account, $provider, $authmap_event->getAuthname(), $authmap_event->getData());
$this->eventDispatcher->dispatch(ExternalAuthEvents::REGISTER, new ExternalAuthRegisterEvent($account, $provider, $authmap_event->getAuthname(), $authmap_event->getData()));
$this->eventDispatcher->dispatch(new ExternalAuthRegisterEvent($account, $provider, $authmap_event->getAuthname(), $authmap_event->getData()), ExternalAuthEvents::REGISTER);
$this->logger->notice('External registration of user %name from provider %provider and authname %authname',
[
'%name' => $account->getAccountName(),
......@@ -145,7 +135,7 @@ public function register($authname, $provider, array $account_data = [], $authma
/**
* {@inheritdoc}
*/
public function loginRegister($authname, $provider, array $account_data = [], $authmap_data = NULL) {
public function loginRegister(string $authname, string $provider, array $account_data = [], $authmap_data = NULL) {
$account = $this->login($authname, $provider);
if (!$account) {
$account = $this->register($authname, $provider, $account_data, $authmap_data);
......@@ -159,23 +149,37 @@ public function loginRegister($authname, $provider, array $account_data = [], $a
*
* @codeCoverageIgnore
*/
public function userLoginFinalize(UserInterface $account, $authname, $provider) {
public function userLoginFinalize(UserInterface $account, string $authname, string $provider): UserInterface {
user_login_finalize($account);
$this->logger->notice('External login of user %name', ['%name' => $account->getAccountName()]);
$this->eventDispatcher->dispatch(ExternalAuthEvents::LOGIN, new ExternalAuthLoginEvent($account, $provider, $authname));
$this->eventDispatcher->dispatch(new ExternalAuthLoginEvent($account, $provider, $authname), ExternalAuthEvents::LOGIN);
return $account;
}
/**
* {@inheritdoc}
*/
public function linkExistingAccount($authname, $provider, UserInterface $account) {
// If a mapping (for the same provider) to this account already exists, we
// silently skip saving this auth mapping.
if (!$this->authmap->get($account->id(), $provider)) {
$authmap_event = $this->eventDispatcher->dispatch(ExternalAuthEvents::AUTHMAP_ALTER, new ExternalAuthAuthmapAlterEvent($provider, $authname, $account->getAccountName(), NULL));
$this->authmap->save($account, $provider, $authmap_event->getAuthname(), $authmap_event->getData());
public function linkExistingAccount(string $authname, string $provider, UserInterface $account) {
// If a mapping (for the same provider) to this account already exists, and
// the authname is the same, we silently skip saving this auth mapping.
$current_authname = $this->authmap->get($account->id(), $provider);
if ($current_authname === $authname) {
return;
}
// If we update the authmap entry, let's log the change.
if (!empty($current_authname)) {
$this->logger->debug('Authmap change (%old => %new) for user %name with uid %uid from provider %provider', [
'%old' => $current_authname,
'%new' => $authname,
'%name' => $account->getAccountName(),
'%uid' => $account->id(),
'%provider' => $provider,
]);
}
$authmap_event = $this->eventDispatcher->dispatch(new ExternalAuthAuthmapAlterEvent($provider, $authname, $account->getAccountName(), NULL), ExternalAuthEvents::AUTHMAP_ALTER);
$this->authmap->save($account, $provider, $authmap_event->getAuthname(), $authmap_event->getData());
}
}
......@@ -5,9 +5,7 @@
use Drupal\user\UserInterface;
/**
* Interface ExternalAuthInterface.
*
* @package Drupal\externalauth
* Interface for the ExternalAuth service.
*/
interface ExternalAuthInterface {
......@@ -22,10 +20,10 @@ interface ExternalAuthInterface {
* @param string $provider
* The module providing external authentication.
*
* @return \Drupal\user\UserInterface
* @return \Drupal\user\UserInterface|bool
* The loaded Drupal user.
*/
public function load($authname, $provider);
public function load(string $authname, string $provider);
/**
* Log a Drupal user in based on an external authname.
......@@ -39,7 +37,7 @@ public function load($authname, $provider);
* @return \Drupal\user\UserInterface|bool
* The logged in Drupal user.
*/
public function login($authname, $provider);
public function login(string $authname, string $provider);
/**
* Register a Drupal user based on an external authname.
......@@ -64,7 +62,7 @@ public function login($authname, $provider);
* @return \Drupal\user\UserInterface
* The registered Drupal user.
*/
public function register($authname, $provider, array $account_data = [], $authmap_data = NULL);
public function register(string $authname, string $provider, array $account_data = [], $authmap_data = NULL);
/**
* Login and optionally register a Drupal user based on an external authname.
......@@ -82,7 +80,7 @@ public function register($authname, $provider, array $account_data = [], $authma
* @return \Drupal\user\UserInterface
* The logged in, and optionally registered, Drupal user.
*/
public function loginRegister($authname, $provider, array $account_data = [], $authmap_data = NULL);
public function loginRegister(string $authname, string $provider, array $account_data = [], $authmap_data = NULL);
/**
* Finalize logging in the external user.
......@@ -102,7 +100,7 @@ public function loginRegister($authname, $provider, array $account_data = [], $a
*
* @codeCoverageIgnore
*/
public function userLoginFinalize(UserInterface $account, $authname, $provider);
public function userLoginFinalize(UserInterface $account, string $authname, string $provider): UserInterface;
/**
* Link a pre-existing Drupal user to a given authname.
......@@ -115,6 +113,6 @@ public function userLoginFinalize(UserInterface $account, $authname, $provider);
* @param \Drupal\user\UserInterface $account
* The existing Drupal account to link.
*/
public function linkExistingAccount($authname, $provider, UserInterface $account);
public function linkExistingAccount(string $authname, string $provider, UserInterface $account);
}
<?php
namespace Drupal\externalauth\Form;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Confirm the user wants to delete an authmap entry.
*/
class AuthmapDeleteForm extends ConfirmFormBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* The EntityTypeManager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Temporary storage for the current authmap entry.
*
* @var array
*/
protected $authmapEntry;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database'),
$container->get('entity_type.manager')
);
}
/**
* Constructs a router for Drupal with access check and upcasting.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection to get authmap entries.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The EntityTypeManager service.
*/
public function __construct(Connection $connection, EntityTypeManagerInterface $entity_type_manager) {
$this->connection = $connection;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'authmap_delete';
}
/**
* {@inheritdoc}
*/
public function getQuestion(): TranslatableMarkup {
if (!empty($this->authmapEntry['uid'])) {
/** @var \Drupal\user\Entity\User $user */
$user = $this->entityTypeManager->getStorage('user')->load($this->authmapEntry['uid']);
}
// We don't display the provider name; in most use cases it's implicit.
return $this->t('Are you sure you want to delete the link between authentication name %id and Drupal user %user?', [
'%id' => $this->authmapEntry['authname'],
'%user' => isset($user) ? $user->getAccountName() : "<unknown> ({$this->authmapEntry['uid']})",
]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl(): Url {
// We want to return a URL object pointing to admin/people/authmap/PROVIDER.
// Url('view.authmap.page', ['provider' => PROVIDER]) instead returns
// admin/people/authmap?provider=PROVIDER, which is not recognized as
// contextual filter value.
return Url::fromUri('internal:/admin/people/authmap/' . $this->authmapEntry['provider']);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state): array {
// This form has uid + provider in its URL, not authname + provider, to not
// expose authnames externally in e.g. HTTP referrer logs.
$authname = FALSE;
$provider = $this->getRouteMatch()->getParameter('provider');
$uid = $this->getRouteMatch()->getParameter('uid');
if ($provider && $uid && filter_var($uid, FILTER_VALIDATE_INT)) {
$authname = $this->connection->select('authmap', 'm')
->fields('m', ['authname'])
->condition('m.uid', (int) $uid)
->condition('m.provider', $provider)
->execute()->fetchField();
}
if ($authname === FALSE) {
// Display same error for either illegal UID or no record.
$this->messenger()->addError($this->t('No authmap record found for provider @provider / uid @uid.', [
'@provider' => $provider,
'@uid' => $uid,
]));
return [];
}
$this->authmapEntry = [
'provider' => $provider,
'authname' => $authname,
'uid' => $uid,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$provider = $this->getRouteMatch()->getParameter('provider');
$uid = $this->getRouteMatch()->getParameter('uid');
if (!$provider || !$uid || filter_var($uid, FILTER_VALIDATE_INT) === FALSE) {
throw new \LogicException('It should be impossible to submit this form without valid provider/uid parameters.');
}
$this->connection->delete('authmap')
->condition('uid', (int) $uid)
->condition('provider', $provider)
->execute();
$this->messenger()->addStatus($this->t('The link has been deleted.'));
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment