Recreating the single sign on logic for generating usernames

AI-generated summary

The discussion revolves around recreating the single sign-on (SSO) logic for generating usernames in Discourse. SwisherSweet wants to pre-populate users from an external SSO system and mimic the username creation process, which automatically generates reasonable usernames. Falco points to the relevant code in GitHub: https://github.com/discourse/discourse/blob/bb0fa5abbc6da2ad32ec52264796ee78d1cf3a45/lib/user_name_suggester.rb. jerdog clarifies that Discourse only automatically generates usernames when SSO is set up and no valid username is supplied. If a username already exists, Discourse creates a variation, as noted in jerdog with Auth0 as an example.

Howdy,

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.

u12345678
u23456789

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?

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?