Salesforce 認証のセットアップ:OAuth2 基本サポートプラグインの使用

OAuth2 Basic Support プラグイン(v2025.11.0 以降の Discourse コアに標準搭載)を使用すると、Salesforce 認証を設定できます。

そのためには、Salesforce 上で接続された OAuth2 アプリを作成します:

  • 作成 → Apps → 新規接続アプリ

  • 「基本情報へのアクセス」を許可することを確認してください

  • 「コールバック URL」を https://YOURFORUM.COM/auth/oauth2_basic/callback に設定します:Discourse フォーラムを HTTPS で実行している必要があります。

  • クライアント ID とシークレットをメモしてください

Discourse 側では、以下の設定(管理 → ログイン → OAuth2.0 の下にあります)を構成してください:

  • oauth2 enabled: true
  • oauth2 client id and secret: 上記セクションで取得したもの
  • oauth2 authorize url: https://login.salesforce.com/services/oauth2/authorize
  • oauth2 token url: https://login.salesforce.com/services/oauth2/token
  • oauth2 fetch user details: true(デフォルトで有効ですが、有効になっていることを確認してください)
  • oauth2 user json url: https://login.salesforce.com/services/oauth2/userinfo
  • oauth2 json user id path: user_id
  • oauth2 json username path: preferred_username
  • oauth2 json name path: name
  • oauth2 json email path: email
  • oauth2 email verified: true
  • oauth2 authorize options: scope, display, immediate, state

問題が発生した場合は、oauth2 debug auth を有効にして /logs を確認してください。

「いいね!」 9

Thanks for this post, which was invaluable in setting up a recent project, which required Salesforce login.

In our case, the Salesforce app was a Community, which meant we had to change some of the details above. I’m posting on this old thread in case it helps anyone else. It nearly broke my brain for a whole day.

  • oauth2 authorize url: https://[COMMUNITY_NAME].force.com/services/oauth2/authorize
  • oauth2 token url: https://[COMMUNITY_NAME].force.com/services/oauth2/token
  • oauth2 callback user id path: id

The path changes were worked out gradually (and painfully) from Salesforce and other documentation:
https://auth0.com/docs/connections/social/salesforce
Help And Training Community

However we still had problems with 403 Forbidden errors, which were plain unstyled HTML and didn’t look very much like a Discourse error to me, which led to much debugging of Salesforce and gnashing of teeth. But the problem was in Discourse.

Forbidden

You don’t have permission to access this resource.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Although the redirect to Callback URL seemed to be working, the browser console registered authentication failures. In the end it was the unset oauth2 callback user id path which was the cause of the authentication failure. Setting it to id fixed everything.

All other settings as in previous post.

「いいね!」 2

ガイドラインをいただきありがとうございます。Salesforce を使用した認証には成功しましたが、問題が発生しました。Salesforce のオブジェクト/フィールドが Discourse に正常に渡されていないようです。Discourse で Salesforce によるログインが成功した直後に、Discourse が新規ユーザーとして扱い、ユーザー名、メールアドレス、名前を要求しています。これらは oauth2 の JSON 内の name、email、username フィールドから取得されるはずです。

oauth2 プラグインで使用する Salesforce のオブジェクト/フィールドの JSON 形式について、ご教示いただけますでしょうか。object.field、object_field、field のみで試してみましたが、エラーは発生しなくても、Salesforce から Discourse へ JSON を通じて何ら情報が渡されず、Discourse でのログインを新規ユーザーとして認識されないようにできていません。

追記ですが、当社の課題に対する解決策を見つけました。SF のフィールドをマッピングするための以下の設定が必要です。

必須設定:

### oauth2 fetch user details - **checked**
### oauth2 user json url - **https://<yoursfsite.com>/services/oauth2/userinfo**
### oauth2 user json url method - **get**
### oauth2 json user id path - **user_id**
### oauth2 json username path - **preferred_username**
### oauth2 json name path - **name**
### oauth2 json email path - **email**

この情報が、oauth2 SF 接続の解決策を探している他の方々のお役に立てれば幸いです。

「いいね!」 2

@sonny.mendoza さん、情報ありがとうございます!これをこのトピックの上部にある手順に統合しました。今後、他の皆さんのお役に立てると思います :slight_smile:

「いいね!」 3