# Programmatically adding users when SSO is being used

**URL:** https://meta.discourse.org/t/programmatically-adding-users-when-sso-is-being-used/79925
**Category:** SSO
**Created:** [February 6, 2018, 4:33pm UTC](https://meta.discourse.org/t/programmatically-adding-users-when-sso-is-being-used/79925 "2018-02-06T16:33:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Philip\_Colmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/philip_colmer/32/120245_2.png) [@Philip\_Colmer](https://meta.discourse.org/u/Philip_Colmer)
#### Post date: [February 6, 2018, 4:33pm UTC](https://meta.discourse.org/t/programmatically-adding-users-when-sso-is-being-used/79925/1 "2018-02-06T16:33:55Z")

</div>

We’ve got our internal copy of Discourse configured so that SSO has to be used, and it is connected to our LDAP server. That means that any member of staff can easily log on using their common username and password … but their account only gets created when they first log on.

There is some discussion internally about trying to elevate social interaction between staff but a lot of the staff are reluctant to do anything other than use email.

So, I’m trying to figure out how to solve the challenge by using Discourse. I’ve already figured out the actual email aspect of it (i.e. configuring Discourse so that categories have their own inbound email address) but I can see two challenges that I’m not sure how to solve:

1. Ideally I’d like everyone to have an account on Discourse _before_ they sign into Discourse. The reason for wanting this is so that if they email Discourse without having an account first, Discourse has the user’s full details rather than treating them as anonymous.

2. I’d like everyone to be able to receive summary emails from Discourse so that they are aware of threads being created (even if they never visit Discourse) … but that also requires the account to exist.

Any suggestions on what I can do? Is there a way I can create accounts in Discourse programmatically so that they tie into SSO when people log on?

Thanks.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 6, 2018, 4:54pm UTC](https://meta.discourse.org/t/programmatically-adding-users-when-sso-is-being-used/79925/2 "2018-02-06T16:54:05Z")

</div>

You can do it via the API. Here’s an example: [GitHub - pfaffman/discourse-user-creator: Create an activated user, optionally assigning to group · GitHub](https://github.com/pfaffman/discourse-user-creator)

---

<div class="post-metadata">

### Author: ![Philip\_Colmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/philip_colmer/32/120245_2.png) [@Philip\_Colmer](https://meta.discourse.org/u/Philip_Colmer)
#### Post date: [February 6, 2018, 4:56pm UTC](https://meta.discourse.org/t/programmatically-adding-users-when-sso-is-being-used/79925/3 "2018-02-06T16:56:26Z")

</div>

Thanks … one issue I can think of is that I have to supply a password when creating the user. Presumably, if SSO is being enforced, Discourse actually ignores the password I’ve provided? (Testing would prove that, I guess!)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 6, 2018, 4:57pm UTC](https://meta.discourse.org/t/programmatically-adding-users-when-sso-is-being-used/79925/4 "2018-02-06T16:57:47Z")

</div>

Yeah. Since you’re using SSO the password won’t matter, or can be omitted. Testing would be the way to prove it! If you’d like help and have a budget, my contact info is in my profile.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [February 6, 2018, 5:04pm UTC](https://meta.discourse.org/t/programmatically-adding-users-when-sso-is-being-used/79925/5 "2018-02-06T17:04:53Z")

</div>

You can create users with the `sync_sso` route. There is some PHP code in this post that gives an example of how to do it: [If someone changes their email in WordPress, change it in Discourse - sso\_sync - #3 by simon](https://meta.discourse.org/t/if-someone-changes-their-email-in-wordpress-change-it-in-discourse-sso-sync/76572/3). In that code, it’s being used to update a user’s email, but the same idea will work to create a new user.
