Fixed user_id key Within xf_user_external_auth


Well-known member
Is it intended that the table has two different unique indexes?

provider + provider_key definitely should be unique, but with user_id being a unique primary key, it means we can never have more than one external auth service per user because XenForo_Model_UserExternal->updateExternalAuthAssociation() does "ON DUPLICATE KEY UPDATE" if the user_id isn't unique even if the provider is different.


XenForo developer
Staff member
That table's weird. I think the primary key should be (user_id, provider). I don't even know if it needs a unique key on (provider, provider_key).


Well-known member

Can you confirm that the PKEY should be (user_id, provider). I am wanting to link multiple external authentication methods to user accounts and want to be sure I am aligned with your schema.


Active member
Here is a simple SQL statement to fix this issue (until it is released formally by XenForo):
ALTER TABLE xf_user_external_auth DROP PRIMARY KEY, ADD PRIMARY KEY (user_id, provider);
Tested that this allowed multiple external identity providers for a single user and does exactly what is described in this thread.