I wanted to raise an issue I am seeing. I work with an organization that commonly deletes Entra accounts for users that leave and recreates them when they come back. Typically the period of absence is over 30 days, so the Entra account cannot be restored when they return. Instead they are recreated with the same UPN/email and other account details. This leads to a situation where a Moodle account may be linked to an Entra account but point to an object ID for the user object that is no longer present. This mismatch leads to unexpected behavior.
I came to notice this because the org enabled the setting Suspend previously synced accounts in Moodle when they are deleted from Microsoft Entra ID, and they reported that some accounts they were manually activating, but they kept getting automatically suspended each day, disrupting the users ability to use the system. I traced this to the scheduled task Suspend/re-enable/delete users based on Microsoft Entra ID status with output like: Suspended jane.doe123 (deleted in Entra ID)
Looking at these accounts:
- in the "Manage User Connections" page they look normal, and show "Synced from Microsoft Entra ID.
Awaiting initial login." (This is because the users were created via the MS365 user sync but do not actually use OIDC auth, they chose to keep using SAML2 that they had already been using before implementing the local_365 plugins)
- inspecting the database table mdl_local_o365_objects, I found the entry for the user has a matching 'o365name' value but contained an object ID that did not match the object ID present in the user's Entra profile
From the testing I've done so far there is no way to easily disconnect the user from the deleted account, since only the "Resync" link is available from the GUI. The only ways fix this per account would be:
- manually delete the rows associated with the user from any of mdl_local_o365_objects and local_auth_oidc_token
- arrange for the user to login via alternate auth, and have them finish connection/disconnect their account from the Microsoft block
- expose OIDC auth and have them log in to complete the connection, then the option to disconnect their account appears for admins in the Manage User Connections page
I understand the plugins need to hold on to the connection to be able to reactivate the Moodle account if the Entra user comes back, but from what I can tell it is not working in the case that the user comes back after 30 days. I am not sure what the best solution is to handle this more gracefully in an automated way would be, but at minimum I wonder if a disconnect option could be added for accounts that are synced from Entra but awaiting login so this could be handled without action from the end user or manual deletion of database rows?
I wanted to raise an issue I am seeing. I work with an organization that commonly deletes Entra accounts for users that leave and recreates them when they come back. Typically the period of absence is over 30 days, so the Entra account cannot be restored when they return. Instead they are recreated with the same UPN/email and other account details. This leads to a situation where a Moodle account may be linked to an Entra account but point to an object ID for the user object that is no longer present. This mismatch leads to unexpected behavior.
I came to notice this because the org enabled the setting Suspend previously synced accounts in Moodle when they are deleted from Microsoft Entra ID, and they reported that some accounts they were manually activating, but they kept getting automatically suspended each day, disrupting the users ability to use the system. I traced this to the scheduled task Suspend/re-enable/delete users based on Microsoft Entra ID status with output like: Suspended jane.doe123 (deleted in Entra ID)
Looking at these accounts:
Awaiting initial login." (This is because the users were created via the MS365 user sync but do not actually use OIDC auth, they chose to keep using SAML2 that they had already been using before implementing the local_365 plugins)
From the testing I've done so far there is no way to easily disconnect the user from the deleted account, since only the "Resync" link is available from the GUI. The only ways fix this per account would be:
I understand the plugins need to hold on to the connection to be able to reactivate the Moodle account if the Entra user comes back, but from what I can tell it is not working in the case that the user comes back after 30 days. I am not sure what the best solution is to handle this more gracefully in an automated way would be, but at minimum I wonder if a disconnect option could be added for accounts that are synced from Entra but awaiting login so this could be handled without action from the end user or manual deletion of database rows?