# Improve Google Login with Multiple Accounts

**URL:** <https://meta.discourse.org/t/improve-google-login-with-multiple-accounts/75964>\
**Category:** Feature\
**Created:** [Décembre 13, 2017, 2:57 UTC](https://meta.discourse.org/t/improve-google-login-with-multiple-accounts/75964 "2017-12-13T14:57:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)\
**Post date:** [Décembre 18, 2017, 1:18 UTC](https://meta.discourse.org/t/improve-google-login-with-multiple-accounts/75964/2 "2017-12-18T13:18:09Z")

</div>

> [@Geoffrey\_Challen](#):
>
> Anyway, it seems like there are a few options here, in order from best to worst:

Another solution would be to always prompt a user to select a Google account, even if they’re only logged into one.

Both that, or:

> [@Geoffrey\_Challen](#):
>
> Implement Google’s domain restriction so that I have to log in using my domain-specific provider

are possible with a handful of lines of code.

Discourse uses the omniauth-google-oauth2 gem for authentication, and as per [its documentation](https://github.com/zquestz/omniauth-google-oauth2/tree/v0.3.1#configuration):

- the first can be done by setting the `prompt` setting to `select_account`
- the second can be done by setting the `hd` setting to the G Suite domain

You pass in these options here, like the `skip_jwt` parameter:

> <https://github.com/discourse/discourse/blob/main/lib/auth/google_oauth2_authenticator.rb#L49>

I imagine the core team will graciously accept a PR doing one or the other if you put them behind a site setting. If you want this _right now_, or are not tracking tests-passed with your instance, then you could implement this in an plugin which registers an auth provider which inherits `Auth::GoogleOAuth2Authenticator` and redefines the `register_middleware` method (or I guess you could even monkey patch that method in your plugin before it’s called instead).

Hope this helps 🙂

---

_[View the full topic](https://meta.discourse.org/t/improve-google-login-with-multiple-accounts/75964)._
