تكوين تسجيل الدخول الأحادي (SSO) مع WP Discourse و DiscourseConnect

The WP Discourse plugin lets you set up DiscourseConnect in Wordpress so your users can use their Wordpress account to log into Discourse, or their Discourse account to log into Wordpress. Before you can set up DiscourseConnect you first have to install the WP Discourse plugin on Wordpress and Connect it to your Discourse. If you’re ready to get started, start by watching this short video, or follow the instructions below.

Next Step

Once you’ve set up DiscourseConnect, you may want to check out the following topics


Instructions

Setting a Secret Key

Whether you’re setting up WP Discourse as the DiscourseConnect Provider or Client, you need to set a secret key. Go to the “DiscourseConnect Secret Key” tab and enter a string of text (numbers, letters, and symbols are all allowed), at least 10 characters long. Use the same rules for creating this as you would to create a strong password. Make sure you save it when you’re done.

Then, open your Discourse Site Settings (in the Admin panel), and search for “discourse connect”. One of the settings near the top will be discourse connect secret. Paste the secret key you set in WP Discourse in there and click the green tick.

Logging into Discourse with Wordpress (DiscourseConnect Provider)

Make sure you’re WP Discourse is connected to your Discourse and your secret key is set ( :point_up: ) before following these instructions

To let your users log into Discourse using their Wordpress account details, you need to setup WP Discourse as the DiscourseConnect Provider. Go to the DiscourseConnect Provider tab in the WP Discourse settings, select the Enable DiscourseConnect Provider checkbox and save your settings.

Next, go to your Discourse Site Settings and enter “discourse connect” into the search box to see all your Discourse DiscourseConnect settings. First, set the discourse connect url to the URL of our Wordpress. The final step is to select enable discourse connect. Make sure you’re ready to go before you select this as once you do, your users will only be able to log in to Discourse using Wordpress.

Once you’ve enabled discourse connect in Discourse, to make sure that it is setup correctly open an incognito window in your browser. Keep your normal (non-incognito) browser window logged in to an admin account (just in case something goes wrong and you need to change the settings back). In the incognito window you’ll notice that the Discourse ‘Sign Up’ button no longer appears. Click on the ‘Log In’ button. You should see a Wordpress login screen. Enter your Wordpress credentials to log in. You should then be redirected back to Discourse and be logged in.

If something goes wrong, or you notice something is not quite right, go back to your normal browser window and disable enable discourse connect to let your users log into Discourse normally. If you’re no longer logged in to your admin account in your normal browser window for some reason, check out the “Disable DiscourseConnect Through the Discourse Console” section in Troubleshooting below to regain access to your Discourse.

Email Verification

Discourse expects all user’s email addresses to be verified and WordPress doesn’t force users to verify their email address. In a default WordPress setup it is fairly easy to verify a user’s email address during the registration process, but if a site is using a plugin that creates a front end registration form - for example, the registration form that can be added with WooCommerce - the WP Discourse plugin isn’t able to verify the user’s email.

In users’ emails aren’t being verified in Wordpress, before a WordPress user will be able to login to the forum, they will need to respond to an email verification notice that is sent out by Discourse. The plugin has a couple of filters that can be used to override this behaviour. Take a look at the code, starting here, for details.

Remove the require_activation flag

If you’re sure that WordPress is authenticating email addresses, you can tell Discourse that it doesn’t need to. To completely remove the require_activation flag, add something like this to your Wordpress (e.g. in your theme’s functions.php file):

// Replace 'my_prefix' with your site prefix.

add_filter( 'discourse_email_verification', 'my_prefix_discourse_email_verification' );
function my_prefix_discourse_email_verification( $require_activation ) {
    return false;
}

To remove the require_activation flag for specific users, use something like this:

// Replace 'my_prefix' with your site prefix.

add_filter( 'discourse_email_verification', 'my_prefix_discourse_email_verification', 10, 2 );
function my_prefix_discourse_email_verification( $require_activation, $user_id ) {
    $user = get_userdata( $user_id );
    if ( /* some condition tested against $user */ ) {

        return true;
    }

    return false;
}

Userdata Webhook

This Webhook exists for historical reasons - having the Discourse Name field automatically filled in can now be accomplished by using the Create or Sync Discourse Users on Login DiscourseConnect Provider option.

The Update Userdata webhook (in the “Webhooks” settings panel) can be used when WordPress is the DiscourseConnect Provider for your Discourse. The webhook automatically fills in the user’s Discourse Name field on WordPress.

Creating an DiscourseConnect Login Link

If you have the DiscourseConnect Provider option enabled, you can add a DiscourseConnect login link to your WordPress site by creating a link with the following structure:

<a href="https://discourse.example.com/session/sso?return_path=/">Community</a>

Set the value of return_path to the page on your forum you would like the user to end up on. You can add an SSO login link to a WordPress menu by adding a URL with this structure as a Custom Link in the Menus section of the WordPress dashboard.

Logging in to WordPress with Discourse (DiscourseConnect Client)

To enable your site to function as an DiscourseConnect Client for Discourse, click on the DiscourseConnect Client tab. On that page, select the Enable DiscourseConnect Client and Add Login Link options.

Now go to your Discourse Admin / Settings page and search for ‘discourse connect’ to see all your DiscourseConnect options.

  • select the ‘enable discourse connect provider’ setting
  • copy your DiscourseConnect Secret Key from WordPress to the ‘secret’ field of the Discourse ‘discourse connect provider secrets’ setting. In that setting’s ‘domain’ field enter your WordPress site’s domain. Then click the green checkmark to save your settings.

When complete, the ‘discourse connect provider secrets’ setting on Discourse should look like this (with the domain set to your WordPress domain):

Discourse should now be functioning as a DiscourseConnect provider for your WordPress site.

Open your Wordpress site in an incognito window in your browser. When you now go to your login page, you should see a ‘Log in with Discourse’ link underneath the login form. Click it and you’ll be taken to the Discourse login form. Login there, and you’ll be redirected back to the WordPress login page with a notice saying that you need to sync your account with Discourse. Follow the instructions in the notice to link your accounts, and you should now be able to log into your WordPress site through Discourse.

Note: this behaviour only affects users who have existing accounts on both WordPress and Discourse. New WordPress accounts that are created through Discourse DiscourseConnect will be able to login freely to WordPress the first time the click the ‘Log in with Discourse’ link. To make it easier for users with existing accounts on both your WordPress site and your Discourse forum to login through Discourse, select the Sync Existing Users by Email checkbox on the DiscourseConnect Client options tab.

Syncing Discourse Logout

When DiscourseConnect is enabled, logout from Discourse can be synced with your WordPress site by adding your site’s home_url with the query parameter request=logout to the Discourse Site Setting logout redirect. The setting is in the Discourse settings section at /admin/site_settings/category/users. Here’s an example ‘logout redirect’ URL:

http://example.com/?request=logout

Troubleshooting

If you’re having issues with using WordPress as the DiscourseConnect provider for your forum, the first things to check are:

  • that the DiscourseConnect Secret keys set on WordPress and Discourse are the same
  • make sure that you have selected Enable DiscourseConnect Provider on your WordPress site
  • make sure you have entered the correct discourse connect url on Discourse.

“Login Error” when using DiscourseConnect

If users are getting a “Login Error” message when they attempt to login to Discourse, please see

Debug and fixing common DiscourseConnect issues.

Disabling DiscourseConnect

If DiscourseConnect isn’t working for you, you can turn it off by disabling the enable discourse connect site setting. If you’re not still logged into an admin account somewhere to turn it off, don’t worry, there’s a few ways you can get back in to turn it off.

Login via /users/admin-login

Open a new browser window and enter your forum URL in the URL bar followed by /users/admin-login, e.g.

https://community.mysite.com/users/admin-login

You should see an input asking you for your admin email. After you submit your email, you’ll receive an email with a link that will allow you to log-in directly to your admin account. You can then go to your site settings and disable enable discourse connect to turn DiscourseConnect off.

If this doesn’t work for some reason, don’t worry, you can still turn DiscourseConnect off via your server’s console (:point_down:)

Turn off DiscourseConnect through the server console

If you don’t know what the server console is, or you don’t have access to it, reach out to your hosting provider for help. After you’ve SSH’d into your server, the commands you need to run are as follows:

cd /var/discourse
./launcher enter app
rails c
SiteSetting.enable_discourse_connect=false
exit
exit
10 إعجابات

ماذا لو لم تكن لدي هذه الخيارات في Discourse الخاص بي؟ :confused:

أهلاً بك @LosHunterros في Meta!

Discourse Connect غير مضمن في خطة الاستضافة الأساسية
Screenshot_20240507_204846_Chrome

4 إعجابات

شكرا على ردك

إعجاب واحد (1)

أحتاج الآن إلى مستوى 101 حقًا. أو نعم أو لا بسيطة.

أحتاج إلى وصول سهل من ووردبريس إلى منتداي لهؤلاء العملاء. نظرًا لأنهم أنشأوا حسابًا في ووردبريس، سأستخدمه كمزود.

لكن لدي مشاكل مع الذكاء الاصطناعي الخاص بـ Discourse الآن. لقد فهمت أن DiscourseConnect سيستولي على جميع عمليات تسجيل الدخول الأخرى، مثل Google و Microsoft والمحلية. لكن الذكاء الاصطناعي متأكد بقوة من أن هذا ليس صحيحًا، إذا قمت بتعيين discourse connect allowed redirect domains.

حسنًا، لقد فعلت ذلك. ولا يزال يتم إعادة التوجيه إلى ووردبريس يحدث دون أي خيارات تسجيل دخول أخرى.

إذًا، هل أضعت ساعتين من حياتي بسبب هلوسة الذكاء الاصطناعي، أم أنني فعلت شيئًا خاطئًا؟ لأنه إذا كنت على حق في البداية ولم يسمح DiscourseConnect بتسجيلات الدخول الأخرى، فسأقوم بإزالته فورًا. العيش بدون تسجيل دخول Google ليس خيارًا في هذه الزاوية من أوروبا.

كانت فكرتك الأولية صحيحة. الذكاء الاصطناعي خاطئ: انظر المزيد.

للأسف، نعم.

إعجاب واحد (1)

لقد اتبعت دليل الإعداد حتى النقطة التي ينبغي أن يعمل فيها تسجيل الدخول الموحد (SSO). عندما أزور موقع Discourse الخاص بي في نافذة متصفح متخفية، يتم توجيهي على الفور إلى الصفحة الرئيسية لموقع WordPress الخاص بي مع سلسلة استعلام طويلة في عنوان URL ولا توجد خيارات تسجيل دخول مرئية.

هل هذا هو السلوك المتوقع في هذه المرحلة؟
هل أحتاج الآن فقط إلى إنهاء بناء جانب WordPress (تسجيل الدخول/التسجيل وما إلى ذلك)، أم أنني أخطأت في التكوين؟

مرحباً مايك، أهلاً بك. يجب أن يتم توجيهك إلى صفحة تسجيل الدخول القياسية لـ Wordpress. أول ما يتبادر إلى الذهن هو أن السمة (theme) الخاصة بك (أو إضافة) توفر صفحة تسجيل دخول مخصصة. كيف تبدو صفحة تسجيل الدخول الخاصة بك عادةً؟

مرحباً أنجوس، شكراً لك! :slight_smile:

هذه عملية تثبيت جديدة لكل من ووردبريس وديسكورس، مع تفعيل سمة Twenty Twenty-Five. لقد اتبعت تعليمات الفيديو الخاصة بك خطوة بخطوة، ولكن عندما أصل إلى ديسكورس في نافذة متصفح متخفية، يتم إعادة التوجيه إلى موقع ووردبريس وتصل إلى الصفحة الرئيسية للسمة، وليس شاشة تسجيل الدخول.

موقع ووردبريس محمي حاليًا بخصوصية الدليل لأنه على بيئة تطوير - هل يمكن أن يؤثر ذلك على إعادة التوجيه إلى صفحة تسجيل الدخول العادية؟

مرحباً مايك، إليك مقطع فيديو قصير سجلته للتو يوضح تثبيتاً عاملاً على الكود الحالي.

فقط قارن الإعداد الخاص بك بما أعرضه في الفيديو وإذا كنت متأكداً من أنك قمت بإعداده بنفس الطريقة ولا يزال لا يعمل، فسوف نمر بعملية استبعاد لمعرفة ما إذا كان بإمكاننا تحديد السبب.

إعجاب واحد (1)

مرحباً أنجيس،

شكراً جزيلاً لك على إعداد هذا الفيديو، دعم رائع!

لقد قدمت لقطات شاشة لكل قسم (مع طمس المعلومات الحساسة)

image

image

image

في الصورة أعلاه، لم يتم تحديد هذا في الواقع (عفواً) ولكن، عندما أزور المنتدى في متصفح التصفح المتخفي، يتم إعادة توجيهي تلقائياً إلى /wp-login.php - لا يتم عرض المنتدى وزر تسجيل الدخول كما هو الحال لديك.

image

لست منزعجاً بشكل مفرط من أنه يذهب مباشرة إلى صفحة wp-login الآن، ولكن الحصول على إمكانية عرض المنتدى مباشرة هو دائماً ميزة إضافية!

@angus لقد اكتشفت الأمر… خلال “ماذا أفعل” الأولي، قمت بحظر المجتمع بهذا؛

image

أعتذر عن كوني مصدر إزعاج، هذه هي وضعية بدء التشغيل :dashing_away:.

شكراً مرة أخرى على الدعم الرائع - أنا متأكد من أنني سأعود.

إعجابَين (2)

سعيد لأنك تمكنت من حلها!

مرحباً أنجوس، أتساءل عما إذا كان بإمكانك المساعدة في هذه المشكلة التي أواجهها، لم أتلق أي رد على موضوعي:

في الأساس، إذا قمت بإخفاء هوية مستخدم، فإن إضافة تسجيل الدخول الموحد (SSO) تقوم بإنشاء حساب جديد له. هل هناك طريقة لتعطيل المستخدمين بشكل فردي لمنع إنشاء حسابات جديدة لهم، وهل يمكن أن تتم المزامنة تلقائيًا عند حظر شخص ما أو إخفاء هويته؟

ربما قم بإخفاء هوية المستخدم ثم اجعل عنوان بريده الإلكتروني هو عنوان SSO. أو اجعل ووردبريس (WordPress) يرفض المستخدم (يبدو هذا هو الحل الحقيقي - يجب أن يرفض ووردبريس المستخدم)

كيف أجعل ووردبريس يمنع المستخدم من تسجيل الدخول عبر تسجيل الدخول الموحد (SSO)؟ هذا هو الحل الذي أعتقده.

هذا سؤال خاص بـ ووردبريس (WordPress). :wink:

لقد بحثت في الإنترنت ويبدو أنه يمكنك تغيير دورهم إلى “لا يوجد دور في هذا الموقع”.

أعلم ما كنت أعنيه، أريد أن يتمكن المستخدم من الاستمرار في استخدام الموقع ولكن لا يمكنه إنشاء حساب في المنتدى.

المنتدى الخاص بنا منفصل عن الموقع، لذا يجب أن يتمكن بعض الأشخاص المحظورين من المجتمع بسبب إحداثهم اضطرابات من الاستمرار في استخدام الموقع وهو أداة برمجيات كخدمة (SaaS).

إذًا أعتقد أنك ستحتاج إلى تعليقها في “ديسكورس” (discourse). إذا كنت بحاجة إلى إخفاء هوية محتواها، فستحتاج إلى القيام بذلك ثم إنشاء الحساب الذي سيتم تعليقه.

مرحباً @Shauny لقد رددت على منشور الدعم الأصلي الخاص بك:

إعجاب واحد (1)