SSO from Wordpress for Two Different Discourse Sites


(Matt) #1

Hi-
I have SSO set up for my multi-site Wordpress via the plugin and @AdamCapriola’s helper class.

I want to have SSO work for two separate Discourse sites from one Wordpress site. Is this possible?

The Discourse sites are hosted on two separate digital ocean droplets.

Thank you!
Matt


(Kane York) #2

Yup, perfectly possible! Just point them to the same SSO endpoint.


(Matt) #3

Thanks but when I do just that I get an error for the second Discourse site. The first Discourse site is entered into @AdamCapriola’s helper class on line 14 as discourse.yciw.net with the corresponding SSO secret on line 13.

When I try to log in to the second Discourse site which has a url of: community.yciw.net I get an error saying “Timeout expired” but the url is going to the first discourse site with this in the browser:
http://discourse.yciw.net/session/sso_login?sso=bm9uY2U9NTg0N2YzOTk4NmZlMDhjMmYxM2U3YjQ0MWU4N2Q5MDQmbmFtZT1FbGlqYStNZWx0emVyJnVzZXJuYW1lPTIyZWxpamFobSZlbWFpbD1uby1yZXBseS0zNjcxJTQweWNpdy5uZXQmYWJvdXRfbWU9JmV4dGVybmFsX2lkPTM2NzE%3D&sig=d58b9141b87c06f3910ae7a546442475d7b0628215d9dd287cbba378af2e3dcd

Here is the helper class: https://github.com/ArmedGuy/discourse_sso_php/blob/master/examples/wordpress.php


(Kane York) #4

Okay, so you’ll have to determine discourse_url from the Referer headers. And you could do that for sso_secret too, or just keep them the same.


(Matt) #5

Thank you. I just don’t know quite how to do that. Is it one of the methods described here
Thanks for you help!


(Steven Greco) #6

I would guess the easiest way would be to create a separate template for the second discourse site.


(Kane York) #7

Hah, didn’t consider that. Yeah that would be easier heh :slight_smile:


(Matt) #8

Thanks @Grex315. Could you help me understand how to add an include statement to the template file itself for the helper class as you mentioned below? I just have the helper class added to my function.php file. Thank you!


(Matt) #9

Would it be:

<?php include 'page_discourse-sso.php';?> add to the template.php file somewhere?

Then I would duplicate the page_discourse-sso.php file and call it page_discourse-sso2.php

And add <?php include 'page_discourse-sso2.php';?> to the template.php file.


(Kane York) #10

Here’s a cleaner implementation.

mysite.com/dc_auth/discourse.php:

$sso_secret = '1234567890';
$discourse_url = 'http://discourse.yciw.net';

include 'sso-common.php';

mysite.com/dc_auth/community.php:

$sso_secret = '0987654321';
$discourse_url = 'http://community.yciw.net';

include 'sso-common.php';

mysite.com/dc_auth/sso-common.php: https://github.com/ArmedGuy/discourse_sso_php/blob/master/examples/wordpress.php


(Steven Greco) #11

yup. the way Kane has it is the way I set mine up. I try and stay away from editing the functions.php file. Just put the include statement right into the wordpress page template for Armed guy’s sso helper class.


(Matt) #12

Thank you that really helped and it is working for me. I’m have one other related error however.
When the user logs in to Wordpress and then goes to the discourse forum and clicks login the user is logged in perfectly.

####However if the user visits the Discourse site first and then click login they are taken to the Wordpress login page as expect but an Invalid Request error is given after attempting to login. This is the resulting url:

http://www.yciw.net/knights/sso2/?sso=bm9uY2U9NGRkOTVkNWRjMGRmMDRhYWY5NWFhNTViZWRlM2YwNGU%3D#038;sig=5baef3f02735f089349739292201d12cb3ddf704723091bf0848e456869254ef

Any ideas?

Thank you!