Setting user locale via SSO

(Sören) #1


is there a way to set the user’s locale when logging in/registering via SSO? I’d like to use Discourse in a multilingual project but it seems like each user would have to set the locale in their preferences manually, which isn’t optimal.
If it’s not possible to do so via the SSO, do you know of an alternative way to accomplish something similar?


New option: auto-select language by HTTP header
(Simon Cossar) #2

I’ve been working on a plugin that sets the locale for non-logged-in users from their browser’s language preferences. It also adds a locale selector to the sign-up form that defaults to the browser’s locale.

The plugin is here: GitHub - scossar/accept-language: A Discourse plugin to set the language for non-logged-in users

You can try it here: Change your browser’s language preferences to see it how it works. I’m updating this site over the next couple of days. If it’s not working it’s probably being rebuilt. The content is mostly filler for now.

There is a topic about this idea here: Variable default interface language for new users

(Sören) #3

I’ve already discovered your plugin earlier and was eager to use it for non-logged-in users. It is my understanding that the sign-up form won’t be displayed when registering a user via SSO, so my users wouldn’t see the form field you added. Am I wrong about that?

Thanks for your answer and your plugin, Simon!

(Simon Cossar) #4

Yes that’s right. I haven’t used SSO with Discourse yet, but from looking at the code it should be possible to change it so that it will set the user’s locale.

(Sören) #5

I’m not yet familiar with the code structure of Discourse. Do you know if there’s a way to hook into the SSO processing with a plugin or do you have to fork the project and implement the changes?
Thanks again!

(Simon Cossar) #6

I think it can be done with a plugin. Discourse creates a user with the parameters that are supplied from the sso endpoint. Discourse single_sign_on needs to accept locale as a parameter and Discourse user needs to be set up to use that locale for creating a user.

I can look at it in the next couple of days and see if it’s something I can do. It seems like a good (friendly) way of getting users onto a forum.

(Florian Bender) #7

If you don’t mind, please create a PR to fix this upstream (instead of extending SSO with a plugin). IMHO this is a core issue and should not be delegated to plugins (however, the other functionality/plugin you propose probably is).