Discourse の公式シングルサインオン DiscourseConnect のセットアップ (sso)

DiscourseConnect は、Discourse のコア機能の一つで、ユーザー登録とログインをすべて別のサイトに完全に委譲する「シングルサインオン(SSO)」を設定できるようにします。これは、プロ、ビジネス、エンタープライズホスティングのお客様 に提供されています。

:information_source: (2021 年 2 月)「Discourse SSO」は現在「DiscourseConnect」となっています。古いバージョンの Discourse を実行している場合、以下の設定名は discourse_connect_... ではなく sso_... となります。

問題点

Discourse サイトと連携しようとする多くのサイトでは、すべてのユーザー登録を別のサイトに保持したいと考えています。このような設定では、すべてのログイン操作をその異なるサイトに委譲する必要があります。

既存の認証と併用して SSO を使用したい場合はどうすればよいですか?

DiscourseConnect の目的は、Discourse の認証を置き換えることです。新しいプロバイダーを追加したい場合は、既存のプラグイン(例:https://meta.discourse.org/t/vk-com-login-vkontakte/12987)を参照してください。

DiscourseConnect の有効化

DiscourseConnect を有効にするには、以下の 3 つの設定を記入する必要があります。

enable_discourse_connect:有効にする必要があります(グローバルスイッチ)
discourse_connect_url:ログイン時にユーザーが転送される外部URL
discourse_connect_secret:SSO ペイロードをハッシュ化するために使用される秘密の文字列。ペイロードの真正性を保証します。

enable_discourse_connect を true に設定すると、以下のようになります。

  • ログインまたはアバターをクリックすると、/session/sso にリダイレクトされ、さらにユーザーが署名付きペイロードとともに discourse_connect_url にリダイレクトされます。
  • ユーザーは「パスワードの変更」を行うことができません。このフィールドはユーザープロフィールから削除されます。
  • ユーザーはもはや Discourse 認証(ユーザー名/パスワード、Google など)を使用できなくなります。

誤ってチェックしてしまった場合はどうすればよいですか?

参照:Log back in as admin after locking yourself out with read-only mode or an invalid SSO configuration

サイトでの DiscourseConnect の実装

:warning: Discourse は、外部ユーザーを Discourse ユーザーにマッピングするために電子メールを使用し、外部電子メールが安全であると仮定しています。外部電子メールを Discourse に送信する前に検証していない場合、サイトは極めて脆弱になります!

または、検証されていない電子メールを送信することを強く主張する場合は、必ず require_activation=true を設定してください。これにより、すべての電子メールが Discourse によって検証されるようになります。ただし、この設定を有効にすることは強く推奨されません。この設定を有効にして進める場合は、大きなリスクを引き受けることになります。

Discourse は、署名付きペイロードとともにクライアントを discourse_connect_url にリダイレクトします(例:discourse_connect_urlhttps://somesite.com/sso の場合)。

以下のような受信トラフィックを受け取ります。

https://somesite.com/sso?sso=PAYLOAD&sig=SIG

ペイロードは、noncereturn_sso_url で構成される Base64 エンコードされた文字列です。ペイロードは常に有効なクエリ文字列です。

例えば、nonce が ABCD の場合、raw_payload は以下のようになります。

nonce=ABCD&return_sso_url=https%3A%2F%2Fdiscourse_site%2Fsession%2Fsso_login。この raw_payload は Base64 エンコードされています。

呼び出されるエンドポイントでは、以下の処理を行う必要があります。

  1. 署名を検証する:discourse_connect_secret を鍵として使用した PAYLOAD の HMAC-SHA256 が sig と等しいことを確認する(sig は hex エンコードされる)。
  2. 必要な認証を実行する。
  3. 少なくとも nonceemailexternal_id を含む新しい URL エンコードされたペイロードを作成する。追加データも提供可能で、Discourse が理解するすべてのキーのリストは以下の通りです。
    • nonce は入力ペイロードからコピーする必要があります。
    • email は検証済みの電子メールアドレスである必要があります。電子メールアドレスが検証されていない場合は、require_activation を「true」に設定してください。
    • external_id は、ユーザー固有の一意の文字列で、電子メールや名前などが変更されても決して変更されない値です。推奨値は、データベースの「id」行番号です。
    • username は、ユーザーが新規の場合、または SiteSetting.auth_overrides_username が設定されている場合に、Discourse 上のユーザー名になります。
    • name は、ユーザーが新規の場合、または SiteSetting.auth_overrides_name が設定されている場合に、Discourse 上のフルネームになります。
    • avatar_url は、ユーザーが新規の場合、または SiteSetting.discourse_connect_overrides_avatar が設定されている場合に、ダウンロードされてユーザーのアバターとして設定されます。
    • avatar_force_update はブール値フィールドです。true に設定すると、avatar_url が変更されたかどうかに関わらず、Discourse がユーザーのアバターを更新することを強制します。
    • bio は、ユーザーが新規の場合、またはユーザーのバイオが空の場合、または SiteSetting.discourse_connect_overrides_bio が設定されている場合に、ユーザーのバイオの内容になります。
    • title は、ユーザーのタイトルを設定します。
    • website は、ユーザーのプロフィール上のウェブサイトを設定します。
    • location は、ユーザーのプロフィール上の所在地を設定します。
    • profile_background_url は、ユーザーが新規の場合、または SiteSetting.discourse_connect_overrides_profile_background が設定されている場合に、ダウンロードされてユーザーのプロフィール背景として設定されます。
    • card_background_url は、ユーザーが新規の場合、または SiteSetting.discourse_connect_overrides_card_background が設定されている場合に、ダウンロードされてユーザーのカード背景として設定されます。
    • locale は、ユーザーが新規の場合、かつ SiteSetting.allow_user_locale が有効になっている場合に、ユーザーのロケールを設定します。
    • locale_force_update はブール値フィールドです。locale とともに true に設定すると、既存のユーザーのロケールを更新することを強制します(SiteSetting.allow_user_locale が必要)。
    • 追加のブール値(「true」または「false」)フィールドには、adminmoderatorsuppress_welcome_messagelogout があります。
  4. ペイロードを Base64 エンコードする。
  5. discourse_connect_secret を鍵として、Base64 エンコードされたペイロードをテキストとして HMAC-SHA256 ハッシュを計算する。
  6. ssosig クエリパラメータとともに return_sso_url にリダイレクトする(http://discourse_site/session/sso_login?sso=payload&sig=sig)。

Discourse は nonce が有効であることを検証し、有効であればすぐに期限切れにして再利用できないようにします。その後、以下の処理を試みます。

  1. SingleSignOnRecord モデルで既に連携されている external_id を検索してユーザーをログインさせる。
  2. 提供された電子メールを使用してユーザーをログインさせる(require_activation = true でない限り)。
  3. ユーザーに対して新しいアカウントを作成する(email、username、name を提供し、external_id を更新する)。

セキュリティ上の懸念

nonce(ワンタイムトークン)は 30 分後に自動的に期限切れになります。つまり、ユーザーがサイトにリダイレクトされてから 30 分以内にログインまたは新規アカウントを作成する必要があります。

このプロトコルは、nonce は一度しか使用できないため、リプレイ攻撃に対して安全です。また、nonce は現在のブラウザセッションに紐付けられているため、CSRF 攻撃から保護されます。

グループメンバーシップの指定

discourse connect overrides groups」オプションが指定されている場合、Discourse は groups に渡されたカンマ区切りのグループリストを考慮します。

groups 以外にも、SSO ペイロード内で add_groupsremove_groups 属性を使用してグループメンバーシップを指定できます。これは「discourse connect overrides groups」オプションの有無に関係なく機能します。

add_groups は、ユーザーがメンバーであることを保証するグループ名のカンマ区切りリストです。
remove_groups は、ユーザーがメンバーでないことを保証するグループ名のカンマ区切りリストです。

リファレンス実装

Discourse には、SSO クラスのリファレンス実装が含まれています。

簡単な実装例は以下の通りです。

class DiscourseSsoController < ApplicationController
  def sso
    secret = "MY_SECRET_STRING"
    sso = DiscourseApi::SingleSignOn.parse(request.query_string, secret)
    sso.email = "user@email.com"
    sso.name = "Bill Hicks"
    sso.username = "bill@hicks.com"
    sso.external_id = "123" # アプリケーションの各ユーザー固有の ID
    sso.sso_secret = secret

    redirect_to sso.to_url("http://l.discourse/session/sso_login")
  end
end

シングルサインオンへの移行と移行後

リクエストペイロードで require_activation パラメータが true に設定されていない限り、システムはシングルサインオンエンドポイントから提供された電子メールを信頼します。つまり、過去に DiscourseConnect が無効な状態で Discourse に既存のアカウントを持っていた場合、DiscourseConnect はそれを再利用し、新しいアカウントを作成することはありません。

DiscourseConnect を無効にした場合、ユーザーはパスワードをリセットしてアカウントにアクセスできるようになります。

実例

以下の設定を想定します。

Discourse ドメイン:http://discuss.example.com
DiscourseConnect URL:http://www.example.com/discourse/sso
DiscourseConnect シークレット:d836444a9e4084d5b224a60c208dce14
電子メール検証:なし(ペイロードに require_activation=true を追加)

ユーザーがログインを試みる

  • nonce が生成される:cb68251eefb5211e58c00ff1395f0c0b

  • raw ペイロードが生成される:nonce=cb68251eefb5211e58c00ff1395f0c0b

  • ペイロードが Base64 エンコードされる:bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGI=

  • ペイロードが URL エンコードされる:bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGI%3D

  • Base64 エンコードされたペイロードに対して HMAC-SHA256 が生成される:1ce1494f94484b6f6a092be9b15ccc1cdafb1f8460a3838fbb0e0883c4390471

最後に、ブラウザは以下にリダイレクトされます。

http://www.example.com/discourse/sso?sso=bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGI%3D&sig=1ce1494f94484b6f6a092be9b15ccc1cdafb1f8460a3838fbb0e0883c4390471

他端での処理

  1. ペイロードが HMAC-SHA256 を使用して検証される。sig が不一致の場合、処理は中止される。
  2. 上記の手順を逆順に実行して nonce を抽出する。

ユーザーがログインする。

name: sam
external_id: hello123
email: test@test.com
username: samsam
require_activation: true

署名なしペイロードが生成される。

nonce=cb68251eefb5211e58c00ff1395f0c0b&name=sam&username=samsam&email=test%40test.com&external_id=hello123&require_activation=true

順序は関係なく、値は URL エンコードされます

ペイロードが Base64 エンコードされる。

bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGImbmFtZT1zYW0mdXNlcm5hbWU9c2Ftc2FtJmVtYWlsPXRlc3QlNDB0ZXN0LmNvbSZleHRlcm5hbF9pZD1oZWxsbzEyMyZyZXF1aXJlX2FjdGl2YXRpb249dHJ1ZQ==

ペイロードが URL エンコードされる。

bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGImbmFtZT1zYW0mdXNlcm5hbWU9c2Ftc2FtJmVtYWlsPXRlc3QlNDB0ZXN0LmNvbSZleHRlcm5hbF9pZD1oZWxsbzEyMyZyZXF1aXJlX2FjdGl2YXRpb249dHJ1ZQ%3D%3D

Base64 エンコードされたペイロードが署名される。

3d7e5ac755a87ae3ccf90272644ed2207984db03cf020377c8b92ff51be3abc3

ブラウザは以下にリダイレクトされる。

http://discuss.example.com/session/sso_login?sso=bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGImbmFtZT1zYW0mdXNlcm5hbWU9c2Ftc2FtJmVtYWlsPXRlc3QlNDB0ZXN0LmNvbSZleHRlcm5hbF9pZD1oZWxsbzEyMyZyZXF1aXJlX2FjdGl2YXRpb249dHJ1ZQ%3D%3D&sig=3d7e5ac755a87ae3ccf90272644ed2207984db03cf020377c8b92ff51be3abc3

DiscourseConnect レコードの同期

POST 管理エンドポイント /admin/users/sync_sso を使用して DiscourseConnect レコードを同期できます。DiscourseConnect エンドポイントに渡すのと同じレコードを渡せばよく、nonce は関係ありません。

他のサイトから admin/users/sync_sso を呼び出す場合は、リクエストのヘッダーに有効な管理者 api_keyapi_username を含める必要があります。リクエストの構造についての詳細は、Sync DiscourseConnect user data with the sync_sso route を参照してください。

DiscourseConnect レコードの削除

DiscourseConnect プロバイダーからの external_id 値が変更された場合(生成アルゴリズムを変更した場合や、異なるエンドポイントの場合など)、Rails コンソールを使用して既存のレコードをすべて安全に削除できます。

SingleSignOnRecord.destroy_all

ユーザーのログアウト

必要に応じて、システム内の任意のユーザーをログアウトさせるために、POST 管理エンドポイント /admin/users/{USER_ID}/log_out を使用できます。

ログアウト時に Discourse がリダイレクトするエンドポイントを構成するには、「logout redirect」設定を検索してください。ここで URL が設定されていない場合、discourse connect url で設定された URL にリダイレクトされます。

external_id によるユーザー検索

ユーザープロフィールデータは /users/by-external/{EXTERNAL_ID}.json エンドポイントを使用してアクセスできます。これにより、user_id を含むユーザー情報を含む JSON ペイロードが返されます。この user_idlog_out エンドポイントで使用できます。

既存の実装

  • discourse_api gem を SSO に使用できます。基本的な実装を確認するには、examples ディレクトリ の SSO コードを参照してください。

  • WordPress プラグイン を使用すると、WordPress と Discourse 間の SSO 設定が簡単になります。設定の詳細は、プラグインのオプションページの SSO タブにあります。

今後の課題

  • 他のプラットフォーム向けの SSO のリファレンス実装をさらに収集したいと考えています。実装をお持ちの場合は、Dev / SSO カテゴリー に投稿してください。

高度な機能

  • フィールド名の前に custom をプレフィックスすることで、カスタムユーザーフィールドを渡すことができます。例えば、custom.user_field_1 は、名前が user_field_1UserCustomField の値を設定するために使用できます。
  • avatar_url を渡してユーザーのアバターを上書きできます(SiteSetting.discourse_connect_overrides_avatar を有効にする必要があります)。アバターはキャッシュされるため、URL が同じでも更新を強制するには avatar_force_update=true を渡してください。現在、ユーザーのアバターを無効にするために空の URL を渡すことはできません。
  • デフォルトでは、SSO 経由で作成されたすべての新規ユーザーにウェルカムメッセージが送信されます。これを抑制したい場合は、suppress_welcome_message=true を渡してください。
  • Discourse インスタンスを Discourse Connect プロバイダーとして設定するには、DiscourseConnect をアイデンティティプロバイダーとして使用する を参照してください。

DiscourseConnect プロバイダーのデバッグ

DiscourseConnect のデバッグを支援するために、サイト設定 verbose_discourse_connect_logging を有効にできます。この設定を有効にすると、YOURSITE.com/logs に詳細な診断情報が表示されます。YOURSITE.com/logs の下部にある「warnings」ボックスに :white_check_mark: することをお忘れなく。

SSO ペイロードの完全なダンプを含む警告をログに記録します。

  • DiscourseConnect プロセスが開始されるたびに、DiscourseConnect ペイロードの完全なダンプを含む警告をログに記録します。
  • ユーザーが DiscourseConnect の完了に失敗するたびに(nonce の期限切れや IP ブロックによる)

:spiral_notepad: ユーザーのサインアップを自動化する必要がありますか?Auto-provisioning user accounts when SSO is enabled を参照してください。

「いいね!」 174
Discourse SSO + normal login
Sync DiscourseConnect user data with the sync_sso route
SSO login & logout issues
Is there a "log_in" SSO API endpoint?
SSO locked me out of Discourse!
What is the SSO login URL
With SSO my user still need to hit the login button
SSO Login page not showing up
How to handle Discourse SSO when the authentication site allows users to change emails?
"User Log out API" return success in response but user session still alive
SSO integration & external profile sync help
SSO on Discourse using Atlassian Crowd
Single Sign-Out?
Mobile (firebase) SSO authentication
Login to Discourse with website account details
Discourse SSO using auth0 via URL
Users who register on my site, register also on Discourse Vise Versa
Custom Login / Registration from another API
Automatically assigning users to a group
SSO and e-mail addresses having a plus sign
Automatic session management with OAuth SSO
Merging users from different forums
Advantage and disadvantage of enabling SSO
About the SSO category
Shibboleth / SAML / SSO -- Working Implementation for Higher Ed
How to generate nonce from client-side Javascript
Logout POST Request
Customized login auth plugin
User Fields to validate users
Enable sso for my site
Disable email verification for SSO
SSO with TownNews CMS
Using existing RoR application for user auth / signup instead of discourse
[PAID] Setup SSO for self-hosted instance
SSO locked me out of Discourse!
Discourse Ruby API testing "Unknown attribute 'auth_token' for User
Switching out authentication for a passwordless alternative
A way for admins to edit users' external IDs
Hashing Secret + Payload for SSO
Will Discourse ask for a username if it's not provided to /session/sso_login?
Categorizing and tracking users
Getting signed data from the server
Getting signed data from the server
SSO and changing email addresses upstream
SSO (maybe) specific issue
SSO (maybe) specific issue
Why isn't Discourse more frequently recommended as a "community platform"?
Integration with .NET MVC application for a SaaS platform
Running my own discourse image
How do I make discourse use my platform's autentication system?
Automatic addition of users to group based on email domain
Allowing people to login using accounts from other websites
Seeking Slack Login / SSO for Discourse
Smooth J/K navigation when using keyboard
SSO to Joomla site
Discourse Connect on Local instance is not working
Implementing SSO for dev environment and troubleshoot
Login with FB, google and apple only
SSO provider implementation - Admin, moderator and groups ignored?
How to divide my community into 2 parts
Using Discourse to add a forum feature to our current application?
Shared cookie SSO: Notifying frontend
User auth with website at root and Discourse in subfolder
Can I authenticate to Drupal via Discourse?
Difficulty of Tiered-access forum
Any way to not require email verification with WP as the SSO Provider?
How to enable sso on discourse?
How to auto-login user in application web view
[PAID] automatically change user email
Create apikey for user programmatically as admin
Bug when visiting same thread url
Open source will support customized provider SSO
Is there a way to get all emails of users with the API?
How can generate _forum_session and _t for an user through code/api call or without login to browser?
Show/hide forums based on the domain? (Shared forum via CNAME)
Integrate with DjangoRest and Vue.js
Connect Discourse Auth with my Django user DB?
Disable account confirm emails when creating users via API
Transforming usernames with SSO
Automatically provision accounts with external SSO provider? (skip Create New Account prompt)
Error ArgumentError in DiscourseSsoController#sso, wrong number of arguments (given 1, expected 0)
Error ArgumentError in DiscourseSsoController#sso, wrong number of arguments (given 1, expected 0)
Embed variables in footer
Need help to setup SSO without emails
Programmatically log users out of discourse
How do I remove people from putting names? I have an API system I want in there
How to detect Discourse user on Ghost Blog?
Problem in sso redirection for compose a new pre-filled topic via URL
How to make default avatars and make sure nobody changes there avatar I want to set them an avatar with my API system
How might we better structure #howto?
Is Roblox Login Possible?
Discourse login with whmcs users
2.7.0.beta4: DiscourseConnect, Topic Timer UI revamp, Login Modal UI revamp, and more
Connecting Discourse invites to Marketo emails
Auto assign member to the certain group
Connecting to an external source of avatars?
Changing avatar_url while sso_overrides_avatar is set?
SSO - User Roles or ACLs to differentiate access levels
SSO - User Roles or ACLs to differentiate access levels
Disabling email verification
SSO Isnt working for me
Could Discourse offer a StackExchange-like SSO/Federated login service?
Mandatory username & avatar generation - How can we do this?
Intergrading discoures in to a application
Configure single sign-on (SSO) with WP Discourse and DiscourseConnect
How to connect to an external database running on localhost
Automate User Creation
Login Help - Correct way to login
What happens to my current users after configuring SSO?
SSO groups without completely overriding
JumpCloud LDAP/SSO
Usernames getting modified – numeral “1” being added
Is "partial" SSO possible?
Send an invite to a user but complete their profile programmatically
Magento 2 as SSO Provider?
Discourse SSO Provider doesn't redirect to return_sso_url as user logs in with custom SSO
Force password change after login
SSO and e-mail addresses having a plus sign
Would Discourse meet all of these niche needs to be a video game community forum?
OpenID Connect and SSO
Does `sso overrides groups` work with Oauth2?
Add user to group after purchase
Shibboleth SSO with Discourse
Using discourse forum in a native app (log-in, languages)
Discourse Connect: How implementing Discourse login with an existing database?
Sync group membership with external list of email addresses
Can I use my own Login page instead of discourse's Default login dialog box?
Modify the URL of 'create your account' button to an external site
How to add a custom url text link on the login page
Can discourse delete archived posts automatically and accept registration without email?
SSO is forcibly creating the user as an admin
Onboarding 15k Trial Users/Year: Need Help Streamlining the Process
Is DiscourseConnect available for self-hosted?
Is DiscourseConnect available for self-hosted?
How to Disable Required SSO Email Activation
User avatar selection through API no longer working
Wordpress plugin not redirect to discourse login automatically
Discourse login by cookie token
Custom field in discourseconnect
Logging users in through c++ desktop application
Invite only by email from database
Is it possible to autologin discourse via iframe?
Login w/ Discourse w/o SSO?
Wordpress plugin not redirect to discourse login automatically
Discourse Hosting Limits?
DiscourseConnect always returns "Nonce is incorrect, ..."
Has anyone succeeded in using discourse as sso provider for nextcloud? Share recipe?
SSO in C# .NET App
Intergrate Discourse with keycloak
Allow my application users to login to discourse
Feature: create default user name from email's user portion when using Google OAuth2/SSO
SSO login appears to have stopped working
Is there a way to use both local login and discourseConnect?
Discourse Hosting Limits?
Changing email addresses not working as an Admin
Populating email field on login page
Problem on SSO Login
SSO Broken - The requested URL or resource could not be found
Adding Discourse to existing Ruby on Rails site
Can I use DiscourseConnect along with Discourse Native Registration?
SSO Login with Discourse
Synchronize SSO login state between Discourse and provider
Connection and discourse account creation without going on discourse
Migrate an IPB 3.1 forum to Discourse
Disable DiscourseConnect
How to use Discourse Connect (SSO) to update avatar, username, name?
Label Sets
Unable to setup discourse in my windows 10
Embed Discourse comments on another website via Javascript
How admin user re-logins after using discourse connect sso and custom domain
How to "intercept" first time SSO usages to let users confirm the SSO action and set a username?
How to create a login on my front-end application to a specific Discourse site?
Use Discourse as an identity provider (SSO, DiscourseConnect)
Connect discourse with magento?
Users allowed to see only some categories
Admin status repeatedly revoked
Plugin to integrate Shopify accounts with Discourse
How to do single sign-on with forum program?
Simple login by email via deep links containing a username
How to set language for SSO users
Want to set internal forum on our reactjs member's platform
New instructions for SSO setup? "enable discourse connect" setting is missing
Add a new user via API
Configure GitHub login for Discourse
Use SSO to auto create Discourse login/password after signed up in my SaaS
How can I change the registration URL?
How do I go about making a very customized theme?
Unable to disable SSO via SSH
Is it possible to have an automatically updating link to a user's profile picture? Such as by giving each user one "slot" for an avatar?
SSO broken after rebuild with stable v3.3.3
Using Discourse Connect with a mobile app
Disable DiscourseConnect
Missing anchor links in certain TOC topics?
Integration into custom auth system where emails are not unique?
WP-Discourse not connected and admin email not recognized
How to disable SMTP during installation?
Auto Login to my Discourse site / subdomain
How to Disable activation_reminder email sending?
Extending header buttons
Auth via Discourse Forum
🧩 How to Build an Android App User Community with Discourse? [HeyApks Project]
Postgres doesn't seem to be running when running Discourse locally using Docker
Discourse sso login redirect to localhost:3000, not 4200 (running via docker)
Cross-Discourse Quoting
Is it Possible to Send Encrypted Email and Password in the Authentication Flow?
Nutzung von Nextcloud aus Discourse heraus
Inherited forum with old Discourse Connect Config and Looking for Some Guidance
Merging user accounts
Understanding PII storage in Discourse
Auto-provisioning user accounts when SSO is enabled
REQUEST: Highly Effective Age Assurance (OneID Phone No. Age Verification) Integration
Intergrate Discourse with keycloak
Auto-sign-in with the OpenId Connect Plugin and AWS Cognito
How can I configure Single Sign On for our App to the Discourse Community Forum
Auto-assign random, anonymous usernames
Communities using discourse SSO for their in-app community experience
Login to Discourse with custom Oauth2 provider
Can I log into multiple instances of discourse simultaneously?
Upgraded last night and login button no longer works
SSO with Roles translating to Groups
Redirect login possible?
How to disable SSO via SSH
Connect Multiple WP Sites To 1 Discourse Installation?
What is the procedure to obtain CAS between my website and my discourse instance?
Problem logging in using SSO plugin
PAID: Create Open Source SSO plugin to auth with Wild Apricot
Trouble connecting drupal and discourse
About the idea: IDENTITY = EMAIL
About the idea: IDENTITY = EMAIL
Consequences of not validating email addresses
SSO and Restricted Groups
Questions about Discourse on Digital Ocean
Require users to join at least one group at sign-up
Use the same user database and login credentials in multiple discourse instances
How to connect my (existing) User Database?
User group sync with drupal
Options with SSO with another custom application
Issues in Integrating SSO in Discourse
How to implement Discourse with an already built Rails project
Updating SSO documentation
Configuring SSO to Work With SocialEngine
Updating SSO documentation
Discourse view file update does not reflect in browser
Discourse view file update does not reflect in browser
Trying to set up SSO
Discourse doesn't re-verify an address changed by SSO
Discourse doesn't re-verify an address changed by SSO
SSO and Discourse Consulting
Changing the unique key to identify users
Setting the user title(group?) based on the information that is coming from the sso payload
Advice needed for tailoring Discourse to my organisation
Primary and Discourse Site Integrations
Automatic Table of Contents generation
Questions Regarding Account Authentication Methods
Redirect all users who click on domain.com/signup to a different page
Poll Result Breakdown
Cant update email via API - invalid_access error
Disabling all emails except those registration related?
Can't get avatar overrides to work over SSO
Conflicting email addresses, giving admins more power to resolve issues
Which Discourse hosting tier should I choose?
New users via API if allow new unchecked
How to change login settings without being logged in?
Data explorer query to list the longest "estimated read time" topics?
Create user in discourse by redirecting from another site
HMAC-256 example on Official SSO page
Add links to meta.discourse.org instructions inside admin
How to configure the SSO Authorization URL via config (without using the admin panel)
TeamAndro exploring a migration from phpBB
DiscourseConnect payload hash encoding mismatch
Disabling SSO in development environment
Getting signed data from the server

こんにちは、どこで見つけるのが難しいのですが、これはどのプロトコルを使用していますか? OAuth2 を想定していますか? パラメータが一致しないようで、プロバイダーから sso= パラメータを受け入れているように見えるというエラーが発生しますか? ヘルプ!

ありがとう

DiscourseConnect は Discourse の SSO の実装です。標準プロトコルは使用しません。

PHP コードを見てもよければ、ここに実装例があります: wp-discourse/lib/sso-provider/discourse-sso.php at main · discourse/wp-discourse · GitHub.

ええ、それはうまくいきません。ユーザー認証に使用したい OAuth2 プロバイダーがある場合は、Discourse OAuth2 Basic プラグインを見てみてください。

「いいね!」 1

@simon 様、ありがとうございます。PHPコードもプロバイダーであり、コンシューマーではないということでしょうか?また、プラグインエリアにあるOIDCプロバイダーも機能する可能性があり、「中間業者」プロバイダーも見かけました。

SSOプロバイダーが標準的でない場合、他のものと連携しないのであれば、誰/何のために意図されているのでしょうか?

重ねてお礼申し上げます!

私がリンクしたコードは、WordPressをDiscourseの認証プロバイダーとして使用するためのものです。

WordPressプラグインは、WordPressをDiscourseConnectクライアントとしても使用できるようにします: wp-discourse/lib/sso-client at main · discourse/wp-discourse · GitHub.

DiscourseにカスタムSSO実装を追加した動機は不明です。ビジネス上の理由があったのだと推測します。

その利点の1つは、外部サイトをDiscourseと緊密に統合できることです。たとえば、ここにリストされているすべてのユーザー属性は、認証プロセス中にDiscourseと同期できます: discourse/lib/discourse_connect_base.rb at 7b89fdead98606d4f47ceb0a1d240d0f6e5f589e · discourse/discourse · GitHub.

また、OAuth2またはOpenID Connectプロバイダーとして設定されていないサイトでも、Discourseでユーザーを認証するために使用できます。

欠点は、認証プロバイダーサイトにカスタムコードを追加する必要があることです。

「いいね!」 1

SSOを提供する外部サイトでメールアドレスを確認しないことによる問題について教えてください。自動スパムを可能にするだけですか?それとも他に考慮すべき点はありますか?外部サイトがメールアドレスを確認しない場合、Discourseがメールアドレス確認を処理しないことが推奨されないのはなぜですか?

追加の洞察があれば教えてください。

私が知る限り、最悪のシナリオは以下の条件を必要とします。

  • 外部サイトでメールアドレスが検証されていない
  • SSOペイロードで require_activation=true が設定されていない
  • Discourseサイトに SingleSignOnRecord が関連付けられていない既存のアカウントがある(アカウント所有者がDiscourseにSSOでログインしたことがない)

この場合、SSOでログインしたことがないDiscourseユーザーのメールアドレスを使用して、外部サイトでサインアップすることができます。これにより、外部サイトの未検証アカウントが、同じメールアドレスを使用しているDiscourseアカウントを乗っ取ることが可能になります。これは、Discourse上の管理者アカウントの場合、特に懸念されるでしょう。

外部サイトがメール検証を処理しない場合は、Discourseがメール検証を処理することが推奨されます。

ただし、メール検証を外部サイトで処理する方が良いのには、いくつかの理由があります。

  • ユーザーにDiscourseからの確認メールを受信させることは、ユーザーが初めてDiscourseにログインしようとするときのわずかな手間になります。(現実的には、その手間はどこかで発生する必要があります。Discourse側か、外部サイト側のどちらかです。)
  • SSOペイロードで require_activationtrue に設定されている場合、Discourseは既存のDiscourseアカウントをメールアドレスに基づいて外部ログインと一致させません。これは、ユーザー名/パスワードで登録してDiscourseにアカウントが作成された後にDiscourseConnectを有効にした場合に問題となります。また、何らかの理由でDiscourse上の SingleSignOnRecord エントリを削除する必要がある場合にも問題となります。ユーザーがDiscourseに再度ログインしようとしても、Discourseは自動的に新しい SingleSignOnRecord エントリを作成しません。
「いいね!」 4

ありがとうございます、@simon さん。大変参考になります!

こんにちは。SSOペイロードのgroupsフィールドについて質問があります。

管理者、モデレーター、信頼レベルなどの自動グループも上書きされますか?それとも保持されますか?

いいえ!その設定の説明が正しければ、手動グループのみに影響します。

「マニュアル」という言葉が説明になかったので、私の用途には有望そうです。試してみて、また報告します。

「いいね!」 1

これを読んだとき、Base64エンコードされたペイロードから直接署名を生成するものだと思っていました。UTF-8バイトから生成する必要があることに気づきませんでした。この点を明確にしていただけますか?

DiscourseConnectを試しています。ドキュメントは素晴らしいです、ありがとうございます。
しかし、いくつか問題にぶつかりました。いくつか助けや説明をいただけると幸いです。

WordPressのDiscourseログインでログインできるようにしたいと考えています(これはうまくいっています :))。しかし、

  • Discourseのサインアップ経由でWordPressユーザーを作成することは可能ですか?(ユーザーがDiscourseユーザーアカウントを作成したときに、自動的にWordPressアカウント/プロファイルも作成され、WordPressにログインできるようになりますか?)

  • WordPressユーザーグループとDiscourseグループを同期することは可能ですか?
    ユーザーがWordPressとDiscourseの両方のユーザーアカウントを持っている場合、DiscourseConnectはそれらを結合できますが、WordPressアカウントに同じ名前のDiscourseグループのユーザーグループを付与しません。また、その逆も同様です。(グループ名が同じでない場合はどうなりますか?ユーザーが「テスト用グループ」というDiscourseグループを持っている場合に、「テストグループ」というユーザーグループをDiscourseConnectに付与するように指示するにはどうすればよいですか?)

何が足りないのでしょうか?

わかりませんが…

注意してください。それは違法な場所であり、サイト所有者以外にとっては広く悪い習慣と見なされています(もちろん😏)、なぜならそれはユーザーの同意と認識なしに起こり、同時にデータがどこかに移動するからです。

確かに、それはいくらかグレーゾーンであり、基本的に、例えばGoogleもそれをやっています。

しかし…なぜですか? WordPress側でDiscourse SSOのみにログインを制限し、ユーザーをDiscourseにリダイレクトしてアカウントを作成すればそれで終わりです。しかし、私の知る限り、ユーザーアカウントを標準で自動的に同期することはできません。そして、なぜそうする必要があるのか、SSOがあればユーザーが必要なときに発生するからです。

私たちのシナリオでは(会員制組織として)

  • WordPressはサブスクリプションの管理、WordPressストアでの商品の購入に使用され、User Groupsを使用して組織内で会員ができることを管理しています。
  • Discourseはフォーラム/オンラインコミュニティであり、Groupsを使用してユーザーがDiscourseのどのエリアにアクセスできるかを制御しています。

現在、新規会員はWordPressアカウント(サブスクリプションなどの設定を含む)とDiscourseアカウントの両方を設定する必要があり、User GroupとDiscourse Groupは手動で管理/同期されています。

新規ユーザーが一度の設定で両方のアカウントを作成でき、User GroupとDiscourse Groupが自動的に同期されるソリューションを探しています。グループ同期についてはAPIなどで解決できると思いますが、複数のユーザーアカウント設定を解決/回避したいと考えています。

それは、DiscourseをWordPressのSSOプロバイダーとして使用しているということのようですね。そのアプローチについては、こちらに概要が記載されています。DiscourseをIDプロバイダー(SSO、DiscourseConnect)として使用する。Discourse WordPressプラグインには、WordPressをDiscourseのSSOプロバイダーとして使用するか、DiscourseをWordPressのIDプロバイダーとして使用するかを選択するオプションがあります。両方のアプローチで同じ名前を使用すると、混乱が生じます。

この場合、WordPressをIDプロバイダーとして使用することをお勧めします。このアプローチでは、ユーザーはWordPressサイトでアカウントを作成し、WordPressの認証情報でDiscourseにログインします。このアプローチで注意すべき点は、ユーザーがDiscourseにログインできるのはWordPress経由のみであり、WordPressアカウントなしでDiscourseアカウントを作成することはできないということです。DiscourseをWordPress会員サイトと統合する場合、これは適切な設定だと思います。

WordPressをDiscourseのIDプロバイダーとして使用する場合、WordPressでのアクティビティに基づいてユーザーのDiscourseグループメンバーシップを設定するのに役立つユーティリティ関数がいくつかあります。これらの関数については、こちらに概要が記載されています。WP Discourse SSOでDiscourseのグループメンバーシップを管理する

元の質問に戻ります。

WordPressプラグインのDiscourseConnectクライアントコードを確認してからしばらく経ちますが、あなたが求めていることは、そのコードが期待どおりに動作する、おおよそそのようになっていると思います。ユーザーがDiscourseアカウントを持っている場合、WordPressの「Discourseでログイン」リンクをクリックするだけでアカウントが作成されます。

これは、WordPressをDiscourseConnectクライアントとして使用する場合、技術的には可能ですが、何か変更されていない限り、ドキュメントで説明されている add_user_to_discourse_group および remove_user_from_discourse_group メソッドを使用することはできません。Discourseグループにユーザーが追加されたときにトリガーされるDiscourse Webhookを設定し、WordPressにそのWebhookを処理するコードを追加する必要があります。WordPressからDiscourseにグループを同期するには、WordPressで変更があったときにユーザーのグループを更新するためにDiscourseにAPI呼び出しを行う必要があります。したがって、WordPressをDiscourseConnectプロバイダーとして使用する場合に比較的簡単に達成できることは、WordPressをDiscourseConnectクライアントとして使用する場合にはやや複雑になる可能性があります。

「いいね!」 1

カスタムログインが使用されている場合を除きます。これは通常、WooCommerce/メンバーシップ/LLMでそのボタンが表示され、Discourse SSOのみを使用するように強制することが標準では行われず、カスタム作業が必要な状況です。

考えられる問題がいくつかあります。1つはキャッシュに関連する問題、もう1つは一部のプラグインによって追加されるログインリダイレクトに関連する問題です。これらの問題に遭遇した場合は、Support > WordPress カテゴリで質問してください。通常は簡単に解決できます。

報告するのを完全に忘れていました。説明どおりに機能し、手動グループのみが影響を受けます。

こんにちは @simon さん、

このSSO機能のPOC(概念実証)での404エラーについて、助けが必要だと思います。この問題に一日中取り組んでいますが、まだ原因を特定できていません。以下のことはできました。

  1. discourse_connect を有効化
  2. discourse_connect_url を https:/ /localhost:4200/login に設定
  3. discourse-connect secret: 20’s (1) 1111111111111111111 (単純にするため)

その後、Angularアプリのログインページで、以下のコードに従ってリクエストを送信しました。


しかし、404 Not Found という応答が返ってきました。

私の理解では、admin/users/sync_sso エンドポイントにPOSTリクエストを送信する際、ユーザーがDiscourseに存在しない場合は、user_idemail に基づいて新しいユーザーを作成し、返される結果は空のオブジェクトではなく、ユーザーオブジェクトであるべきです。ステータスコードは404ではありません。
ログも確認しましたが、この失敗した応答に関連する情報は提供されていませんでした。

よろしくお願いします!