Skip to content

Commit

Permalink
Plugin: Azure Active Directory: Add auto-provisioning (creation) of u…
Browse files Browse the repository at this point in the history
…sers from Azure (as students)
  • Loading branch information
ywarnier committed Mar 2, 2021
1 parent a02e4e4 commit 6aeea96
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
9 changes: 9 additions & 0 deletions plugin/azure_active_directory/CHANGELOG.md
@@ -0,0 +1,9 @@
# Azure Active Directory Changelog

## 2.2 - 2021-03-02

* Added provisioning setting

## 2.1 - 2020

* Initial tested implementation of Azure Active Directory single sign on
4 changes: 3 additions & 1 deletion plugin/azure_active_directory/src/AzureActiveDirectory.php
Expand Up @@ -19,6 +19,7 @@ class AzureActiveDirectory extends Plugin
const SETTING_FORCE_LOGOUT_BUTTON = 'force_logout';
const SETTING_MANAGEMENT_LOGIN_ENABLE = 'management_login_enable';
const SETTING_MANAGEMENT_LOGIN_NAME = 'management_login_name';
const SETTING_PROVISION_USERS = 'provisioning';

const URL_TYPE_AUTHORIZE = 'login';
const URL_TYPE_LOGOUT = 'logout';
Expand All @@ -39,9 +40,10 @@ protected function __construct()
self::SETTING_FORCE_LOGOUT_BUTTON => 'boolean',
self::SETTING_MANAGEMENT_LOGIN_ENABLE => 'boolean',
self::SETTING_MANAGEMENT_LOGIN_NAME => 'text',
self::SETTING_PROVISION_USERS => 'boolean',
];

parent::__construct('2.1', 'Angel Fernando Quiroz Campos', $settings);
parent::__construct('2.2', 'Angel Fernando Quiroz Campos', $settings);
}

/**
Expand Down
29 changes: 28 additions & 1 deletion plugin/azure_active_directory/src/callback.php
Expand Up @@ -74,7 +74,34 @@
}*/

if (empty($userId)) {
throw new Exception('User not found when checking the extra fields.');
if ($plugin->get(AzureActiveDirectory::SETTING_PROVISION_USERS)) {
// Create user
$userId = UserManager::create_user(
$me['givenName'],
$me['surname'],
STUDENT,
$me['mail'],
$me['mailNickname'],
'',
null,
null,
$me['telephoneNumber'],
null,
'azure',
null,
($me['accountEnabled'] ? 1 : 0),
null,
[
AzureActiveDirectory::EXTRA_FIELD_ORGANISATION_EMAIL => $me['mail'],
AzureActiveDirectory::EXTRA_FIELD_AZURE_ID => $me['mailNickname'],
]
);
if (!$userId) {
throw new Exception(get_lang('UserNotAdded').' '.$me['mailNickname']);
}
} else {
throw new Exception('User not found when checking the extra fields.');
}
}

$userInfo = api_get_user_info($userId);
Expand Down

0 comments on commit 6aeea96

Please sign in to comment.