Fixing Microsoft 365 and Teams Login and OAuth Errors in Moodle
The recurring Microsoft 365 and Teams login and OAuth failures in Moodle, and where to fix each one in the Entra app registration and the auth_oidc plugin.
The Microsoft 365 integration connects Moodle to Entra ID (formerly Azure AD) for single sign-on and to Teams for meetings and sync. When it works it is invisible; when it breaks, the errors are cryptic and the fix is almost always in the Entra app registration rather than in Moodle. This guide covers the recurring login and OAuth failures and where to fix each one.
The integration is two plugins, and credentials live in auth_oidc
The first thing to get right, because it determines where every fix happens: the Microsoft 365 integration is two Moodle plugins working together:
- OpenID Connect (
auth_oidc): the authentication plugin. This is the actual OAuth/OIDC client. It owns the login flow, the redirect URI, and the fields where the Entra application credentials are entered. On its settings page these fields are labeled Application ID (your Entra Application/client ID) and Client Secret (the secret value; some providers, and the local_o365 setup wizard, also call this the “Key”). - Microsoft 365 Integration (
local_o365): the back-end. It contains the functions that talk to Microsoft 365 services (Teams, calendar, OneDrive, sync) and depends on auth_oidc. It does not own the redirect URI and is not where the client secret is stored.
A common mistake (including in a lot of troubleshooting write-ups) is to attribute the OAuth client role, the redirect URI, or the client secret to local_o365. They belong to auth_oidc. When you are pasting credentials or checking the redirect URI, you are in the OpenID Connect (auth_oidc) settings: Site administration > Plugins > Authentication > OpenID Connect.
Note also that Moodle core has a separate, unrelated “OAuth 2 Microsoft service” under Site administration > Server > OAuth 2 services (listed alongside Google and others). That is a lightweight Microsoft login/OneDrive feature and is not the auth_oidc + local_o365 Teams/M365 integration. Do not configure the Teams integration there.
You will need access to the Microsoft Entra admin center for the tenant, with rights to edit the app registration and grant admin consent.
Error: redirect URI mismatch
Symptom: login bounces to Microsoft, then fails on the way back with an error mentioning the reply/redirect URL, or lands on a Moodle error page after authenticating.
Cause: the redirect URI registered in Entra does not exactly match the one Moodle sends.
Fix:
- The redirect URI for this integration is your Moodle site address followed by
/auth/oidc/, for examplehttps://your-moodle-site.example.com/auth/oidc/. (This is owned by auth_oidc; you can confirm it on the OpenID Connect plugin’s configuration page.) - In the Entra app registration, open Authentication > Redirect URIs and confirm that exact URL is present, including:
– https, not http – the trailing slash – the www / non-www form that matches your $CFG->wwwroot exactly
- A mismatch of a single character (or a
wwwrootthat does not match the address users actually visit) is enough to break the round trip.
Error: invalid client secret / expired credentials
Symptom: login worked for months, then suddenly fails for everyone with a client-authentication or invalid-secret error.
Cause: the client secret (Key) expired. Entra caps client-secret lifetime at a maximum of 24 months and recommends shorter (often 6 months). When the secret expires, the trust silently dies on its expiry date.
Fix:
- In the app registration, open Certificates & secrets, create a new client secret, and copy its value immediately (it is shown only once).
- Paste the new secret into the Client Secret field on Moodle’s OpenID Connect (auth_oidc) configuration page (not local_o365).
- Note the new expiry date somewhere you will see it before it lapses. Recurring outages every 6 or 12 months are almost always an unmanaged secret rotation. (auth_oidc also supports certificate-based authentication as a longer-lived alternative to a client secret.)
Error: insufficient permissions / admin consent required
Symptom: login or sync fails with a consent or permissions error, or Teams/calendar features specifically do not work while basic SSO does.
Cause: the app registration is missing a required Microsoft Graph API permission, or the permissions are present but admin consent has not been granted for the tenant.
Fix:
- In the app registration, open API permissions.
- Confirm the Graph permissions the integration requires for the features you use are listed.
- Click Grant admin consent for [tenant] (the local_o365 Setup tab also exposes a “Provide Admin Consent” step that does the same thing). Until an administrator consents, delegated permissions that require it fail even though they appear configured.
- Re-test. If basic login now works but Teams sync still fails, the missing permission was Teams-specific.
Error: tenant or account restrictions
Symptom: some users log in fine, others are rejected; or all external/guest accounts fail.
Cause: the app registration’s supported account types or conditional-access policies exclude the accounts that are failing. A single-tenant registration rejects accounts from other tenants by design.
Fix: confirm the app’s supported account types matches your user population, and check with your Entra administrator whether a conditional-access policy is blocking the sign-in. This is a tenant-governance decision, not a Moodle setting.
Error: token validation fails intermittently (clock skew)
Symptom: sporadic, hard-to-reproduce authentication failures with no config change behind them.
Cause: the Moodle server clock has drifted. OIDC tokens carry validity windows (nbf/exp); if the server clock is off by more than the allowed leeway, valid tokens are rejected.
Fix: confirm NTP / time sync is running on the Moodle server and the clock is accurate. A one-line check that resolves a class of “it fails randomly” reports.
The triage order
Login broken for everyone, suddenly? Check the client secret expiry first (in the OpenID Connect plugin settings). Broken after a URL or wwwroot change? Check the redirect URI (/auth/oidc/). Login works but Teams/calendar does not? Graph API permissions and admin consent. Some users only? Account types / conditional access. Random and intermittent? Server clock.
Solin specializes in Moodle authentication, SSO, and Microsoft 365 integration. Need help? Contact us.
Need help with a Moodle or Totara project?
Contact us