Changing the unique key to identify users


(shahid) #1

Hi

I am planning on migrating users over to discourse.

Which field in the db does discourse use to uniquely identify a user account?
I need to use a common id across multiple apps to link everything up so may need to change the unique key to that value…

regards


(Felix Freiberger) #2

This sounds like you want to use SSO.

If you follow that approach, you have two options:

  • Discourse can be managing user accounts. In this case, Discourse should be made the SSO provider. All other apps will have to use Discourse’s internal user id. (You should never attempt to modify the identifier of existing users, though.)
  • Discourse can use another app’s user database. In this case, the other app needs to implement the SSO protocol. In that case, you can just pass the id the external app uses internally to Discourse, and Discourse will remember it and use it to recognize the user later. (If the id is not found, Discourse will look at the email address.)

I’d recommend the latter approach because it’s a bit more flexible :slight_smile:


(shahid) #3

So going for option 2, if the id is not found and discourse uses the email, next time round will it work off the id?


(Felix Freiberger) #4

Yes. More specifically, when the user logs in, this is what happens:

  1. Is a user with this external id already known? If so, log in. Otherwise, continue.
  2. If a user with this email already known? If so, associate the external id with the account, and log in. Otherwise, continue.
  3. Create an account with the specified email and store the external id. Then, log in.