在使用单点登录(SSO)时以编程方式添加用户

我们已将内部 Discourse 副本配置为必须使用 SSO,并连接到我们的 LDAP 服务器。这意味着任何员工都可以轻松使用其通用用户名和密码登录……但他们的账户仅在首次登录时创建。

内部有一些关于尝试加强员工之间社交互动的讨论,但许多员工除了使用电子邮件外,不愿参与其他活动。

因此,我正在尝试找出如何利用 Discourse 解决这一挑战。我已经解决了实际的电子邮件方面(即配置 Discourse,使每个类别拥有自己的入站电子邮件地址),但我看到两个尚未确定如何解决的挑战:

  1. 理想情况下,我希望每个人在登录 Discourse 之前就拥有 Discourse 账户。这样做的目的是,如果他们在拥有账户之前通过电子邮件联系 Discourse,Discourse 能够获取用户的完整信息,而不是将其视为匿名用户。

  2. 我希望每个人都能接收来自 Discourse 的摘要邮件,以便他们了解新创建的讨论主题(即使他们从未访问过 Discourse)……但这同样要求账户已存在。

关于我能做什么,有什么建议吗?我是否可以通过编程方式在 Discourse 中创建账户,以便在人们登录时与 SSO 关联?

谢谢。

1 个赞

You can do it via the API. Here’s an example: GitHub - pfaffman/discourse-user-creator: Create an activated user, optionally assigning to group

3 个赞

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!)

1 个赞

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.

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. In that code, it’s being used to update a user’s email, but the same idea will work to create a new user.

5 个赞