How to Change Moodle Azure AD Tenancy

I need to switch a UAT instance of Moodle to an alternative Azure AD Tenancy, this is how I went about it.

See my original post here on how to setup the app registration in Azure here then head to /admin/settings.php?section=local_o365 within the Moodle instance which you want to change over

In the below you need to change over you Application ID & Application Key, you get these from Azure

Lower down on the same page you need to also change these two fields to the new Tenancy and Sharepoint URL

Then Save the page at the very bottom.

Now on your instances Moodle database you need to run something like the following to change all your existing users over to the new Tenancy

#SQL to change all students to new UPN format

update mdl_user
set username =
REPLACE(username, '@.xxx.ac.uk', '@.xxx.ac.uk')
WHERE auth = 'oidc'
AND username regexp '^[0-9]{8}\@.xxx.ac.uk$'
AND email like '%@xxx.xxx.ac.uk';

#SQL to change all staff to new UPN format

update mdl_user
set username =
REPLACE(username, '@.xxx.ac.uk', '@.xxx.ac.uk')
WHERE auth = 'oidc'
AND username regexp '^[0-9]{8}\@.xxx.ac.uk$'
AND email like '%@xxx.ac.uk';

Check that this has had the desired effect in /admin/user.php and try to login to the site with the alternative UPN ID – remember in a incognito tab / private browser window on your browser of choice.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s