Moodle 3.7: The existing token for this user does not contain a valid user ID

Moodle 3.7: The existing token for this user does not contain a valid user ID

by Ahmad Moussa -
Number of replies: 3

Dear Moodlers,

Kindly need your help to fix the following error. The error is shown after a user logs in using Office 365 SSO, mostly all users can login using their Office 365 accounts expect 3 users they are receiving this same error.... I tried to delete the user then create it again but same error comes up.. How can I fix this issue? I am using Moodle 3.7, PHP 7.2 , MySQL 5.6, CentOS

Your cooperation and support is highly appreciated.

----------------------------------

The existing token for this user does not contain a valid user ID. Please contact your administrator.

More information about this error

error/auth oidc/exception tokenemptyuserid

This page does not exist yet. You can search for this page title in other pages, or let us know by posting about it in one of the Moodle community forums.

------------------------------


Average of ratings: -
In reply to Ahmad Moussa

Re: Moodle 3.7: The existing token for this user does not contain a valid user ID

by Barry Matthias -
Hello

This is usually caused by the oidc token database table recording the wrong user id for the oidc username, try searching the database in table auth_oidc_token as per below

select * from auth_oidc_token where oidcusername=
check the resulting data has the users correct moodle userid if it doesnt delete the entry
Average of ratings: Useful (2)
In reply to Barry Matthias

Re: Moodle 3.7: The existing token for this user does not contain a valid user ID

by Ahmad Moussa -
Dear Barry,

Thank you for your great support. Deleting the entry which has "0" userid fixed the issue. Also I have tried to copy the userid for the same user in user database to auth_oidc_token and it worked perfectly.

When the user logged in again, a new token entry is created. My issue was a result of bad alias and renaming of some users who left our school.
In reply to Ahmad Moussa

Re: Moodle 3.7: The existing token for this user does not contain a valid user ID

by erika alarcon -
Picture of Testers

I updated the auth_oidc plugin and it gave me the error "The existing token for this user does not contain a valid user ID".

Upon checking I saw that in the auth_oidc_token table the userid field was added and in all records it was set to 0.

I deleted all the records in that table and problem solved.