WP Discourse와 DiscourseConnect로 단일 로그인(SSO) 구성하기

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
11개의 좋아요

What if i don’t have those options in my Discourse? :confused:

Hey @LosHunterros, welcome to Meta!

Discourse Connect is not included in the basic hosting plan
Screenshot_20240507_204846_Chrome

4개의 좋아요

Thanks for your response

1개의 좋아요

Now I need really 101 level. Or simple yes or no.

I need easy access from WordPress to my forum for those customers. Because they have created an account in WordPress I would use it as a provider.

But I have problems with AI of Discourse now. I’ve understood that DiscourseConnect will hijack all other logins, as Google, Microsoft and local. But AI is really strongly sure that is not true, if I set discourse connect allowed redirect domains.

Well, I did. And still redirecting to Wordpress happens without any other login options.

So, did I waste two hours of my life because of hallucination of an AI, or have I done something wrong? Because if I was right in the beginning and DiscourseConnect doesn’t allow other logins, I take it off rightaway. Living without Google login isn’t an option in this corner of Europe.

Your initial thought was right. The AI is wrong: See further.

Unfortunately, yes.

1개의 좋아요

설정 가이드를 따라 SSO가 작동해야 하는 단계까지 진행했습니다. 하지만 시크릿 창에서 Discourse 사이트를 방문하면 긴 쿼리 문자열이 포함된 URL로 WordPress 첫 페이지로 즉시 리디렉션되며, 로그인 옵션이 보이지 않습니다.

이 단계에서 이런 동작이 예상되는 것인가요?
이제 WordPress 쪽(로그인/가입 등)을 완성하기만 하면 되는 건가요, 아니면 무언가를 잘못 설정한 건가요?

마이크, 환영해. 표준 워드프레스 로그인 페이지로 리다이렉트되어야 해. 바로 떠오르는 건 네 테마(또는 플러그인)가 사용자 정의 로그인 페이지를 제공하고 있다는 거야. 평소 로그인 페이지는 어떤 모습이었어?

안녕하세요, Angus님! 감사합니다. :slight_smile:

WordPress와 Discourse 모두 새로 설치했으며, Twenty Twenty-Five 테마가 활성화되어 있습니다. 영상 안내에 따라 단계별로 진행했지만, 인코그니토 창에서 Discourse에 접속하면 WordPress 사이트로 리다이렉트되어 로그인 화면이 아닌 테마의 홈 페이지에 도착합니다.

WordPress 사이트는 개발 환경에 있으므로 현재 디렉터리 프라이버시 설정이 적용되어 있습니다. 이것이 정상적인 로그인 페이지로의 리다이렉트에 영향을 주고 있을까요?

마이크, 지금 막 녹화한 영상 하나 보내줄게. 현재 코드로 정상적으로 설치된 모습을 보여주고 있어.

영상에서 보여준 내용과 내 설정을 비교해 봐. 똑같이 설정했는데도 여전히 작동하지 않는다고 확신한다면, 원인을 파악할 수 있도록 하나씩 점검해 나가자.

1개의 좋아요

안거스님,

영상을 올려주셔서 정말 감사합니다. 멋진 지원이었어요!

각 섹션의 스크린샷을 첨부했습니다(민감한 정보는 흐림 처리했습니다).

위 스크린샷에서는 실제로 선택이 되어 있지 않았습니다(아, 실수했어요). 하지만 시크릿 브라우저로 포럼에 접속하면 이제 자동으로 /wp-login.php 페이지로 리디렉션됩니다. 님이 보시는 것과 같은 포럼과 로그인 버튼이 표시되지 않아요.

이제 바로 wp-login 페이지로 이동하는 것은 크게 신경 쓰이지 않지만, 포럼에 직접 액세스할 수 있으면 항상 좋은 점이죠!

@angus 해결했어요… 처음에 “지금 뭐 하고 있는 거지?” 하고 헤매던 중에 이걸로 커뮤니티를 잠가버렸네요;

image

스타트업 모드에서 귀찮은 짓을 해서 죄송합니다 :dashing_away: .

다시 한번 멋진 지원에 감사드립니다 - 또 찾아올 거예요.

2개의 좋아요

해결해서 다행이에요!

안녕하세요, Angus. 이 문제에 대해 도움을 주실 수 있을까요? 제가 작성한 주제에 아직까지 답변이 없습니다:

기본적으로 사용자를 익명 처리하면 SSO 플러그인이 해당 사용자에게 새 계정을 다시 생성합니다. 특정 사용자에게만 계정 생성을 방지하기 위해 개별적으로 사용자를 비활성화하는 방법이 있을까요? 그리고 누군가를 차단하거나 익명 처리할 때 자동으로 동기화될 수도 있을까요?

사용자를 익명화한 다음 이메일 주소를 SSO 이메일로 설정하는 방법도 있습니다. 아니면 WordPress에서 해당 사용자를 차단하는 방법(이것이 진정한 해결책인 것 같습니다. WordPress는 사용자를 거부해야 합니다)도 있습니다.

WordPress에서 사용자가 SSO를 통해 로그인하는 것을 어떻게 차단할 수 있을까요? 그게 해결책이라고 생각합니다.

그건 워드프레스 관련 질문이에요. :wink:

인터넷을 찾아봤는데, 역할을 "이 사이트에서 역할 없음"으로 변경할 수 있는 것 같아요.

아, 내 의도를 좀 더 명확히 설명하자면, 사용자는 웹사이트를 계속 사용할 수 있도록 하되 포럼 계정을 생성하지 못하게 하고 싶습니다.

우리 포럼은 웹사이트와 분리되어 있어서, 커뮤니티에서 문제를 일으켜 제명된 사람들도 SaaS 도구인 웹사이트는 계속 사용할 수 있도록 해야 합니다.

그럼 discourse에서 그들을 정지해야 할 것 같습니다. 그들의 콘텐츠를 익명화해야 한다면, 그렇게 한 후 정지된 계정을 생성해야 합니다.

안녕하세요, @Shauny. 원래 지원 게시글에 답변을 남겼습니다:

1개의 좋아요