Recreating the single sign on logic for generating usernames


I’m pre-populating users in Discourse from an integrated SSO external system and would like to mimic the username creation process in Discourse.

Currently, I’m having to create usernames like so, where the number is the unique user id.


I tried using portions of name or email but always ended up with complaints about special characters.

When a user logs into the site using SSO, the username is automagically created. The username is a reasonable representation of the user and I’d like to copy this functionality with my pre-populated users.

Does anyone know what the logic is and/or can point me to the code in GIT that performs the magic?

Thank you.

Here you go:


So if I understand this correctly, Discourse automagically does this when you have SSO setup/integrated?

1 Like

Only if you don’t supply a valid username.


Ok - so if we use SSO (Auth0) and when it goes to create a username, if there’s one already existing in Discourse with that name then it will create a different one, like a variation?