Skip to content

Commit c492a14

Browse files
committed
Plugin: Azure: Allows the user to be verified based on the internal Azure ID - refs BT#21930
1 parent d17817a commit c492a14

File tree

7 files changed

+39
-2
lines changed

7 files changed

+39
-2
lines changed

main/auth/external_login/login.azure.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
api_not_allowed(true);
1313
}
1414

15+
$uidField = new ExtraFieldValue('user');
16+
$uidValue = $uidField->get_values_by_handler_and_field_variable(
17+
$uData['user_id'],
18+
AzureActiveDirectory::EXTRA_FIELD_AZURE_UID
19+
);
20+
21+
if (empty($uidValue) || empty($uidValue['value'])) {
22+
api_not_allowed(true);
23+
}
24+
1525
$azureIdField = new ExtraFieldValue('user');
1626
$azureIdValue = $azureIdField->get_values_by_handler_and_field_variable(
1727
$uData['user_id'],

plugin/azure_active_directory/lang/dutch.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
$strings['management_login_name_help'] = 'De standaardinstelling is "Beheer login".';
2525
$strings['OrganisationEmail'] = 'Organisatie e-mail';
2626
$strings['AzureId'] = 'Azure ID (mailNickname)';
27+
$strings['AzureUid'] = 'Azure UID (internal ID)';
2728
$strings['ManagementLogin'] = 'Beheer Login';
2829
$strings['InvalidId'] = 'Deze identificatie is niet geldig (verkeerde log-in of wachtwoord). Errocode: AZMNF';
2930
$strings['provisioning'] = 'Geautomatiseerde inrichting';

plugin/azure_active_directory/lang/english.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
$strings['management_login_name_help'] = 'The default is "Management Login".';
2525
$strings['OrganisationEmail'] = 'Organisation e-mail';
2626
$strings['AzureId'] = 'Azure ID (mailNickname)';
27+
$strings['AzureUid'] = 'Azure UID (internal ID)';
2728
$strings['ManagementLogin'] = 'Management Login';
2829
$strings['InvalidId'] = 'Login failed - incorrect login or password. Errocode: AZMNF';
2930
$strings['provisioning'] = 'Automated provisioning';

plugin/azure_active_directory/lang/french.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
$strings['management_login_name_help'] = 'Le nom par défaut est "Login de gestion".';
2525
$strings['OrganisationEmail'] = 'E-mail professionnel';
2626
$strings['AzureId'] = 'ID Azure (mailNickname)';
27+
$strings['AzureUid'] = 'Azure UID (internal ID)';
2728
$strings['ManagementLogin'] = 'Login de gestion';
2829
$strings['InvalidId'] = 'Échec du login - nom d\'utilisateur ou mot de passe incorrect. Errocode: AZMNF';
2930
$strings['provisioning'] = 'Création automatisée';

plugin/azure_active_directory/lang/spanish.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
$strings['management_login_name_help'] = 'El nombre por defecto es "Login de gestión".';
2525
$strings['OrganisationEmail'] = 'E-mail profesional';
2626
$strings['AzureId'] = 'ID Azure (mailNickname)';
27+
$strings['AzureUid'] = 'UID Azure (ID interno)';
2728
$strings['ManagementLogin'] = 'Login de gestión';
2829
$strings['InvalidId'] = 'Problema en el login - nombre de usuario o contraseña incorrecto. Errocode: AZMNF';
2930
$strings['provisioning'] = 'Creación automatizada';

plugin/azure_active_directory/src/AzureActiveDirectory.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class AzureActiveDirectory extends Plugin
2929

3030
public const EXTRA_FIELD_ORGANISATION_EMAIL = 'organisationemail';
3131
public const EXTRA_FIELD_AZURE_ID = 'azure_id';
32+
public const EXTRA_FIELD_AZURE_UID = 'azure_uid';
3233

3334
/**
3435
* AzureActiveDirectory constructor.
@@ -123,5 +124,11 @@ public function install()
123124
$this->get_lang('AzureId'),
124125
''
125126
);
127+
UserManager::create_extra_field(
128+
self::EXTRA_FIELD_AZURE_UID,
129+
ExtraField::FIELD_TYPE_TEXT,
130+
$this->get_lang('AzureUid'),
131+
''
132+
);
126133
}
127134
}

plugin/azure_active_directory/src/callback.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@
7979
throw new Exception('The mail field is empty in Azure AD and is needed to set the organisation email for this user.');
8080
}
8181
if (empty($me['mailNickname'])) {
82-
throw new Exception('The mailNickname field is empty in Azure AD and is needed to set the unique Azure ID for this user.');
82+
throw new Exception('The mailNickname field is empty in Azure AD and is needed to set the unique username for this user.');
83+
}
84+
if (empty($me['objectId'])) {
85+
throw new Exception('The id field is empty in Azure AD and is needed to set the unique Azure ID for this user.');
8386
}
8487

8588
$extraFieldValue = new ExtraFieldValue('user');
@@ -91,6 +94,10 @@
9194
AzureActiveDirectory::EXTRA_FIELD_AZURE_ID,
9295
$me['mailNickname']
9396
);
97+
$uidValue = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
98+
AzureActiveDirectory::EXTRA_FIELD_AZURE_UID,
99+
$me['objectId']
100+
);
94101

95102
$userId = null;
96103
// Get the user ID (if any) from the EXTRA_FIELD_ORGANISATION_EMAIL extra
@@ -107,6 +114,14 @@
107114
}
108115
}
109116

117+
if (empty($userId)) {
118+
// If the previous step didn't work, get the user ID from
119+
// EXTRA_FIELD_AZURE_UID
120+
if (!empty($uidValue) && isset($uidValue['item_id'])) {
121+
$userId = $uidValue['item_id'];
122+
}
123+
}
124+
110125
if (empty($userId)) {
111126
// If we didn't find the user
112127
if ($plugin->get(AzureActiveDirectory::SETTING_PROVISION_USERS) === 'true') {
@@ -155,6 +170,7 @@
155170
[
156171
'extra_'.AzureActiveDirectory::EXTRA_FIELD_ORGANISATION_EMAIL => $me['mail'],
157172
'extra_'.AzureActiveDirectory::EXTRA_FIELD_AZURE_ID => $me['mailNickname'],
173+
'extra_'.AzureActiveDirectory::EXTRA_FIELD_AZURE_UID => $me['id'],
158174
],
159175
null,
160176
null,
@@ -164,7 +180,7 @@
164180
throw new Exception(get_lang('UserNotAdded').' '.$me['mailNickname']);
165181
}
166182
} else {
167-
throw new Exception('User not found when checking the extra fields from '.$me['mail'].' or '.$me['mailNickname'].'.');
183+
throw new Exception('User not found when checking the extra fields from '.$me['mail'].' or '.$me['mailNickname'].' or '.$me['id'].'.');
168184
}
169185
}
170186

0 commit comments

Comments
 (0)