# SSO users aren't automatically added to email domain-based groups

**URL:** https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980
**Category:** Bug
**Created:** [28.Июль.2017 02:33:29 UTC](https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980 "2017-07-28T02:33:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![barryvan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barryvan/32/82635_2.png) [@barryvan](https://meta.discourse.org/u/barryvan)
#### Post date: [28.Июль.2017 02:33:29 UTC](https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980/1 "2017-07-28T02:33:29Z")

</div>

When a user is created via SSO, it appears that their membership in groups based on their email domain isn’t firing.

That is, I have a group set up like so:

 ![image](https://global.discourse-cdn.com/meta/original/3X/f/1/f1e0119eeef86133f5475b4efc3a8b722c3ea6b6.png)

…but users coming in via SSO don’t seem to be added to this group automatically:

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/c/bce4e38c9c9e2291be95dff6914f138b1fe58c35.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/2/b29dd8f5fb38095ab56fde241c9a9e7e3580b2f6.png)

It looks as though there was a discussion around this last year in relation to the “moderator” SSO flag and membership:

> [@Users are not added to the moderators groups when registering with SSO](https://meta.discourse.org/t/users-are-not-added-to-the-moderators-groups-when-registering-with-sso/40165):
>
> Steps to reproduce: Have SSO set up. Let a new user sign in, and specify that he is a moderator in the payload. Expected results: The users has exactly the same permissions as if he signed up and was instantly manually awarded moderator permissions. Actual results: The user is given the moderator flag, but is not added to the staff or moderator groups. This means that he cannot access categories requiring these permissions. Here’s a screenshot of the user settings: It looks lik…

…but this is about everyday, run-of-the-mill users who I want to be in a group so they get flair and specific category access.

---

<div class="post-metadata">

### Author: ![sebastien](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@sebastien](https://meta.discourse.org/u/sebastien)
#### Post date: [17.Октябрь.2017 02:52:22 UTC](https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980/3 "2017-10-17T02:52:22Z")

</div>

I have the same issue. It seems that unregistered users who used SSO to login cannot be added automatically to groups!

UPDATE: now I can identity four use cases:

1/ New users without account validation: users are **not** automatically added to groups  
2/ New users with account validation: users will be added automatically to groups

3/ Existing users (provisioned by the SSO engine): users are **not** automatically added to groups  
3/ Existing users (fully registered): users are added automatically to groups

When enabling SSO (with no account validation) it seems that the “auto-assign user to group” feature is turned off.

Is this the expected behavior? If not is there a workaround.

Regards,  
Seb

---

<div class="post-metadata">

### Author: ![sebastien](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@sebastien](https://meta.discourse.org/u/sebastien)
#### Post date: [19.Октябрь.2017 08:28:38 UTC](https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980/4 "2017-10-19T08:28:38Z")

</div>

@barryvan did you find a workaround for this issue?

---

<div class="post-metadata">

### Author: ![mbb70](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@mbb70](https://meta.discourse.org/u/mbb70)
#### Post date: [20.Октябрь.2017 17:14:55 UTC](https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980/5 "2017-10-20T17:14:55Z")

</div>

Hi @sebastien,

When you are generating your SSO payload, you can set the `add_groups` field based on your user’s email, where `add_groups` is a comma delimited string of groups. I haven’t seen any documentation on this but the code is pretty clear:

> <https://github.com/discourse/discourse/blob/9813f9f0f8c9f4b446aa9f50e5c447161db0c7d5/app/models/discourse_single_sign_on.rb#L110-L119>

That was our workaround to this issue and it has been working so far.

---

<div class="post-metadata">

### Author: ![sebastien](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@sebastien](https://meta.discourse.org/u/sebastien)
#### Post date: [24.Октябрь.2017 09:59:36 UTC](https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980/6 "2017-10-24T09:59:36Z")

</div>

It works but I had to add some custom code to our SSO engine :(!

Thx for the help!

Seb

---

<div class="post-metadata">

### Author: ![alehandrof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alehandrof/32/119526_2.png) [@alehandrof](https://meta.discourse.org/u/alehandrof)
#### Post date: [15.Январь.2018 10:51:06 UTC](https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980/8 "2018-01-15T10:51:06Z")

</div>

I just came across some weird behavior that’s probably related to this bug as well. I’ll look into including groups in the payload, as suggested.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [05.Июль.2018 14:22:53 UTC](https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980/9 "2018-07-05T14:22:53Z")

</div>

This has been fixed a while ago

[https://github.com/discourse/discourse/commit/a28c58feb18f49a7b599fce819fc437b39bddcee](https://github.com/discourse/discourse/commit/a28c58feb18f49a7b599fce819fc437b39bddcee)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [05.Июль.2018 14:22:57 UTC](https://meta.discourse.org/t/sso-users-arent-automatically-added-to-email-domain-based-groups/66980/10 "2018-07-05T14:22:57Z")

</div>


