Discourse OpenID Connect (OIDC)

:discourse2: Summary Discourse OpenID Connect allows an OpenID Connect provider to be used as an authentication provider for Discourse.
:open_book: Install Guide This plugin is bundled with Discourse core. There is no need to install the plugin separately.

Features

The plugin aims to provide a minimal implementation of the specification. Specifically, it supports the “Authorization Code Flow”. To get started, follow the plugin installation instructions, or contact your hosting provider.

Our oauth2-basic plugin can be used for connecting to some openid-connect providers (OpenID Connect is based on OAuth2). However, this plugin should require far less manual configuration, and can make use of the JWT “ID Token” if a JSON API is not available.

Configuration is automatically performed using an OpenID Connect Discovery Document. According to the specification, this should be located at <issuer domain>/.well-known/openid-configuration, but Discourse supports any path to allow for non-compliant implementations (e.g. Azure B2C). The discovery document is cached for 10 minutes, to improve performance on high-traffic sites.

If the discovery document includes a userinfo_endpoint parameter, then the plugin will use that to collect user metadata. If not, the plugin will extract metadata from the id_token (A JWT) supplied by the token endpoint. The plugin DOES NOT verify the authenticity of the JWT signature, as this would significantly increase complexity. This decision is supported by the specification:

If the ID Token is received via direct communication between the Client and the Token Endpoint (which it is in this flow), the TLS server validation MAY be used to validate the issuer in place of checking the token signature.

Configuration

Basic Configuration Options

  • openid_connect_enabled: Enable OpenID Connect authentication

  • openid_connect_discovery_document: OpenID Connect discovery document URL. Normally located at https://your.domain/.well-known/openid-configuration

  • openid_connect_client_id: OpenID Connect client ID

  • openid_connect_client_secret: OpenID Connect client secret

  • openid connect rp initiated logout: Redirect the user to end_session_endpoint after logout. Must be supported by your identity provider and included in the discovery document.

  • openid connect rp initiated logout redirect: (optional) The post_logout_redirect_uri which will be passed to the logout endpoint. If provided, it must be registered with the identity provider.

  • openid_connect_authorize_scope: The scopes sent to the authorize endpoint. This must include ‘openid’

  • openid_connect_use_pkce: Enable Proof Key for Code Exchange (PKCE) for OpenID Connect authentication.

  • openid_connect_verbose_logging: Log detailed openid-connect authentication information to /logs. Keep this disabled during normal use.

Advanced Configuration Options

  • openid_connect_token_scope: The scopes sent when requesting the token endpoint. The official specification does not require this.

  • openid_connect_error_redirects: If the callback error_reason contains the first parameter, the user will be redirected to the URL in the second parameter. Used for unusual implementations that send errors in response to user input (e.g. Azure B2C)

  • openid_connect_allow_association_change: Allow users to disconnect and reconnect their Discourse accounts from the OpenID Connect provider

Example setup

Here we will set up the openid-connect plugin to connect to Google’s OpenID Connect provider. This replicates functionality that already exists in the core of Discourse, but it serves as an accessible example.

  1. Head to OpenID Connect  |  Sign in with Google  |  Google for Developers and follow the instructions to obtain OAuth Credentials.

  2. On the same page, follow the instructions to add a redirect URI. This should be https://<your_forum>/auth/oidc/callback (without a trailing slash)

  3. Go to your Discourse site settings and search for “openid_connect”

    • openid connect enabled:

    • openid connect discovery document: https://accounts.google.com/.well-known/openid-configuration

    • openid connect client id: <client-id>

    • openid connect client secret: <client-secret>

    • openid connect authorize scope: openid email (with a space in between)

  4. You’re done. The “Login with OpenID Connect” button will now log in using Google :tada:. These same steps can be applied to other providers, with very minimal changes.

Debugging

In addition to the verbose_logging setting described above, you can access data about OIDC associations using the data-explorer plugin:

SELECT user_id, provider_name, provider_uid
FROM user_associated_accounts
WHERE provider_name = 'oidc'

Or on the rails console:

User.find_by_username("david").user_associated_accounts.where(provider_name: 'oidc')

Provider Specific Notes

Please feel free to update this if you find any provider-specific quirks relating to this integration:

Entra ID (formerly Azure AD)

Add the email scope, and make sure you’re using the version 2 endpoint configuration document. For example

https://login.microsoftonline.com/{tenant}/v2.0/.well-known/openid-configuration
Azure B2C

The discovery document URL details can be found here: Web sign in with OpenID Connect - Azure AD B2C | Microsoft Learn

To make emails work:

Yahoo
  1. Head to Login - Sign in to Yahoo and create a new app

  2. Enter the Application Name, and set the callback domain to your forum domain (e.g. meta.discourse.org)

  3. Under API Permissions, choose Profiles: Read/Write Public and Private. This is the only way I know of to obtain the user email address

  4. Save the app

  5. In the Discourse OIDC settings, set the discovery document to

    https://login.yahoo.com/.well-known/openid-configuration
    
  6. Enter the client ID and secret from Yahoo

  7. Enable the OIDC plugin

AWS Cognito
  1. Go to Cognito and select or create a new user pool.
  2. Define an app in App clients.
  3. Leave everything to default, but change Auth Flows Configuration to only select ALLOW_REFRESH_TOKEN_AUTH.
  4. Go to app client settings and select the new app.
  5. Change the callback URL to https://yoursite.example.com/auth/oidc/callback.
  6. Only check the Authorization code grant flow among “Allowed OAuth Flows”.
  7. Check all scopes needed (I have all checked).
Okta
  1. Configure Discourse with your Okta app client ID and secret

  2. Set the discovery document URL to

    https://{your-app}.okta.com/.well-known/openid-configuration
    
  3. In Discourse, set the openid connect authorize scope to openid email

:discourse2: Hosted by us? This plugin is available on our Business and Enterprise plans. OAuth 2.0 & OpenID Connect Support | Discourse - Civilized Discussion

Last edited by @pedro 2025-08-29T23:26:31Z

Check documentPerform check on document:
「いいね!」 51

こんにちは。
AWS上のDiscourseインスタンスでOpenID Connect認証プラグインを使用しています。
Discourse、Discourse Sidekiq、Redisのコンテナ(Bitnamiベースですが、どうか追い出さないでください ;))をデプロイしました。DBはAWS RDSで稼働しています。KeyCloakを使用しています。

動作はしています。

しかし、Discourse AWSタスクを再起動した後、キャッシュにDiscoveryドキュメントがあると認識しているのに、実際にはドキュメントが存在しないという状況が時々発生します。そして、KeyCloakから再取得しようとしません。

OIDC Log: Discovery document loaded from cache
OIDC Log: Discovery document is
---
(oidc) Request phase initiated.
(oidc) Authentication failure! openid_connect_discovery_error: OmniAuth::OpenIDConnect::DiscoveryError, Discovery document is missing

ブラウザアプリには、「IDプロバイダーから設定を取得できませんでした。もう一度お試しください。」と表示されます。

何かアドバイスはありますか?

「いいね!」 2

こんにちは。

Discourse のユーザーアバターソースを OpenID サービスで指定されたフィールドに設定する方法はありますか?

編集:Keycloak を使用しています。

「いいね!」 1

こんにちは。

Tomáš_Guba さんと同様の要件があります。ユーザープロファイル内のカスタムエントリから値を取得し、それを [custom] ユーザーフィールドで使用したいと考えています。

私の場合は、userinfo_endpoint を持つディスカバリー ドキュメントがあります。

プラグインのロードマップにそのようなものはありますか?

よろしくお願いします。

「いいね!」 1

こんにちは。プラグインをSSO OpenIDで動作させることができましたが、他のシステムのユーザー名フィールドやメールアドレスなどのフィールドには入力されません。

「openid connect claims」フィールドで何かを設定する必要があると思いますが、このフィールドを直接設定する方法がわかりません。例を教えていただけますか?私のプロジェクトのスクリーンショットをいくつか紹介します。
https://imgur.com/gallery/LWvkJUV

「いいね!」 1

プライベート投稿にログインする際に、元のルートを「失う」のを避ける方法はありますか?

プライベートページにアクセスし、そのページにあるログインボタンのいずれかをクリックすると、サイトにリダイレクトされたときにカテゴリページにたどり着きます。

こんにちは @david さん、

以下の投稿で言及されている問題を確認していただけますでしょうか? OAuth basic の代わりに OIDC プラグインを使用したいのですが、同様の問題が発生しています。/authorize リクエストにパラメータを渡すことができません。プラグインに foo=bar の形式で値を入力しました。

LinkedInでこれを機能させることができませんでした。他の誰かが試したことがありますか?「サインイン…」ボタンをクリックしてLinkedInにリダイレクトされた後、LinkedInにログインし、アプリがLinkedInから私のメールを使用することを「許可」すると、「申し訳ありませんが、アカウントの承認中にエラーが発生しました。もう一度お試しください。」というメッセージが表示されます。

https:/discourse.mysite.com/auth/failure?message=invalid_credentials&origin=https%3A%2F%2Fdiscourse.mysite.com%2F&strategy=oidc

これでもまだ問題があります。次のエラーが表示されます。

(oidc) Authentication failure! invalid_credentials: OAuth2::Error, invalid_request: A required parameter "client_secret" is missing {"error":"invalid_request","error_description":"A required parameter

これはomniauthのエラーで、おそらくこれに関連しているようです: No longer works with oauth2 gem v2.0+ · Issue #68 · decioferreira/omniauth-linkedin-oauth2 · GitHub

助けていただけると幸いです!

エラーが発生しています。


(oidc) 認証失敗! openid_connect_discovery_error: OmniAuth::OpenIDConnect::DiscoveryError, Discovery document is missing

OIDC ログ: Discovery document の取得中にエラーが発生しました Faraday::ConnectionFailed FinalDestination: lookup failed

管理設定で「openid connect discovery document」を https://<auth_provider>/.well-known/openid-configuration に設定しており、これは実行中のアプリのDockerコンテナ内でCurlコマンドやRailsコンソールから正常にアクセスできます。

なぜこれらのエラーが発生するのか、何か考えはありますか?このせいで正しく統合できません。また、イントラネットの後ろにいて、会社のプロキシを使用しています(もしそれが役立つなら)。コンテナのENVでプロキシを有効にすると、「openid connect discovery document」URLに正常にアクセスできます。

「いいね!」 1

2件の投稿が新しいトピックに分割されました: 複数のOIDCソースを許可する

投稿が新しいトピックに分割されました:OIDCを使用したアバターの上書き

こんにちは!

新しい質問です。このプラグインはセッション管理を扱いますか? (Final: OpenID Connect Session Management 1.0)。
OPがsession_stateデータを送信したとしても、コードのどこにもクッキーとして保存されている箇所が見当たらないため、そうではないと思います。

これは質問/機能リクエストです :slight_smile: 素晴らしいものになるでしょう!

「いいね!」 2

このプラグインをAWS Cognitoで使用する場合、ログアウト時にCognitoはログアウトURLにclient_idパラメータを渡す必要があります。私の知る限り、ログアウトURLに追加のクエリパラメータを追加する方法はありません。これは正しいですか?もしそうでない場合、この機能を追加することは可能ですか?

皆さん、こんにちは :wave:t3:

このプラグインの拡張機能(技術的にはテーマ/コンポーネントの形式)を作成しました。これは、ログインポップアップの「OIDC経由でログイン」ボタンを非表示にし、代わりに特別なURLにアクセスすることでログインフローを開始するものです。

discourse-autooidc.zip (1.0 KB)

この機能のユースケースは、会社のメンバーに安全で便利な(自動的な)OAuth経由のログインを提供することです。公開されているOAuthプロバイダーへのリンク(この場合はAuthentikですが、Authelia、Keycloak、Auth0、Oktaなどでも機能するはずです)を公開することなく、また、決して使用できない、または使用すべきでないログイン via oidc ボタンで他のすべてのユーザーを煩わせることなく実現します。

OIDC経由でログインするには、https://<your-discourse-base-url>/login#autooidc を呼び出すだけです。

「いいね!」 3

GitHub - discourse/discourse-hide-auth-method: A theme component which allows hiding a specific login method from the UI, without fully disabling it は同様のことを行っているので、興味があるかもしれません。

「いいね!」 3

Keycloak は Backchannel logout URL をサポートしています。

このレルム(end_session_endpoint 経由)にログアウトリクエストが送信されたときに、クライアントが自身をログアウトさせる URL。省略された場合、このケースではクライアントにログアウトリクエストは送信されません。

このプラグインが、Keycloak からペイロードを受け入れて、すぐに一部のユーザーをすべてのセッションからログアウトさせるエンドポイントを公開してくれると素晴らしいです。そうでない場合、Keycloak でユーザーを無効にした場合、maximum session age(デフォルトでかなり大きい)を待つ必要があります。

ユーザーの管理者ページ(例:/admin/-1/system)からすべてのセッションからログアウトさせることもできます。ページ上部にある「ログアウト」ボタンをクリックしてください。

こんにちは。

ディスカバリー ドキュメントの取得に失敗した場合(タイムアウトなど)、プラグインはエラーをキャッシュします。これは、認証が10分間利用できないことを意味します。エラーをキャッシュしないようにして、より早く再試行できるようにすることは可能ですか?

よろしく

お手数おかけして申し訳ありませんが、PKCEサポートを追加するための簡単なマージで済むオープンなPRがあります。

@nbianca リポジトリの最新のコミッターであることに気づきました。もしよろしければ、ご確認いただけますでしょうか? :folded_hands:

「いいね!」 1