1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed user_id key Within xf_user_external_auth

Discussion in 'Resolved Bug Reports' started by digitalpoint, Dec 14, 2011.

  1. digitalpoint

    digitalpoint 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.
     
    Floren and BamaStangGuy like this.
  2. Mike

    Mike 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).
     
  3. Mike

    Mike XenForo Developer Staff Member

    Nevermind on the (provider, provider_key) -- obviously we need that to do look ups. I'll just change the PKEY now.
     
    digitalpoint likes this.
  4. Deebs

    Deebs Well-Known Member

    Mike,

    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.
     
  5. Mike

    Mike XenForo Developer Staff Member

    Correct.
     
  6. Deebs

    Deebs Well-Known Member

    Thanks, I'll go ahead and change the PKEY.
     
  7. Morgan

    Morgan Active Member

    Here is a simple SQL statement to fix this issue (until it is released formally by XenForo):
    Code:
    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.
     
    Sebastian Cork likes this.

Share This Page