Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
# modDiscourseSSO
Single-Sign-On Extra for MODX Revolution that integrates the brilliant Discourse forums.

This extra requires MODX 2.3+ and PHP5.5+
Single-Sign-On Extra for MODX Revolution that integrates the brilliant Discourse forums.

This extra requires MODX 2.3+ and PHP 5.5+. It still works with MODX 3.x, Discourse 3.x. and PHP 8.3.

Instructions
-
## Instructions

- Download and install Discourse as shown here: https://blog.discourse.org/2014/04/install-discourse-in-under-30-minutes/
- Install this extra via the MODX package manager
- Set your discourse host name, your secret code, and your scheme (http or https) for modDiscourseSSO in the MODX system settings.
- Create a resource called "Discourse" (or anything you like) and add the snippet ```[[!discourse? &loginPage=`54`]]``` to either the resource content field or directly to the template.
- If you haven't already, create a resource to contain your MODX login form. The resource id of this page should be entered into &loginPage parameter of the snippet.
- Also a resource that contains a logout snippet. (For example you can use the one from the Login Extra.)
- Set your discourse host name, your secret code (a long random string), and your scheme (http or https) for modDiscourseSSO in the MODX system settings.
- Create a resource called "Discourse" (or anything you like) and add the snippet ```[[!discourse? &loginPage=`<login_id>`]]``` to either the resource content field or directly to the template. `<login_id>` has to be replaced with the resource id of your MODX login page.
- If you haven't already, create a resource to contain your MODX login form. The resource id of this page should be entered into the &loginPage parameter of the discourse snippet call.
- Also create a resource that contains a logout snippet. For example you can use the one from the Login Extra.
- Fill out the SSO settings within Discourse as shown here: https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045
- The sso_secret should be the same as the one you added to MODX
- The sso_url should be the full URL where your ```[[!discourse? &loginPage=`54`]]``` snippet resides.
- The sso_secret should be the same as the one you added to MODX.
- The sso_url should be the full URL where your ```[[!discourse? &loginPage=`<login_id>`]]``` snippet call resides.
- Also set the "logout redirect" setting (under Users) should contain the full URL of your MODX logout snippet.
- The next time you load Discourse (while logged into MODX) you'll see your MODX account details showing up in Discourse.


Parameters
-
## Snippet parameters

- ```&loginPage``` - This is the resource id of your MODX login page. Unauthorized users will be redirected to this page. If the parameter is not included with the snippet the value of the login_page system setting will be used instead. This param will also accept a URL in case the page you want to redirect to is outside of MODX.

130 changes: 72 additions & 58 deletions _build/config.json
Original file line number Diff line number Diff line change
@@ -1,60 +1,74 @@
{
"name": "modDiscourseSSO",
"lowCaseName": "moddiscoursesso",
"description": "Single Sign On integration for Discourse forums.",
"author": "Murray Wood",
"version": "1.0.0",
"package":{


"menus": [],



"elements": {


"plugins": [],




"snippets": [{
"name":"discourse",
"file":"discourse.snippet.php"
}],




"chunks": [

]


},

"systemSettings": [{
"key": "secret"
,"type": "textfield"
,"area": "default"
,"value": ""
},{
"key": "host"
,"type": "textfield"
,"area": "default"
,"value": "discourse.example.com"
},{
"key": "scheme"
,"type": "textfield"
,"area": "default"
,"value": "http"
},{
"key": "login_page"
,"type": "textfield"
,"area": "default"
,"value": "{site_start}"
}]
"name": "modDiscourseSSO",
"lowCaseName": "moddiscoursesso",
"description": "Single Sign On integration for Discourse forums.",
"author": "Murray Wood",
"version": "1.1.0",
"package": {
"menus": [],
"elements": {
"plugins": [],
"snippets": [
{
"name": "discourse",
"file": "discourse.snippet.php",
"properties": [
{
"name": "loginPage",
"value": ""
}
]
}
],
"chunks": [
]
},
"systemSettings": [
{
"key": "secret",
"type": "textfield",
"area": "default",
"value": ""
},
{
"key": "host",
"type": "textfield",
"area": "default",
"value": "discourse.example.com"
},
{
"key": "scheme",
"type": "textfield",
"area": "default",
"value": "https"
},
{
"key": "login_page",
"type": "textfield",
"area": "default",
"value": "{site_start}"
},
{
"key": "sso_parameters",
"type": "textarea",
"area": "default",
"value": ""
}
]
},
"dependencies": [
{
"name": "php",
"version": ">=5.5"
},
{
"name": "modx",
"version": ">=2.3"
}

}
],
"build": {
"readme": "docs/readme.md",
"license": "docs/license.md",
"changelog": "docs/changelog.md"
}
}
Binary file added _packages/moddiscoursesso-1.1.0-pl.transport.zip
Binary file not shown.
24 changes: 24 additions & 0 deletions core/components/moddiscoursesso/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2025-10-09

### Added

- Add moddiscoursesso.sso_parameters system setting.

## [1.0.0] - 2017-10-24

### Added

- Initial release with main functions working.

## [0.0.1] - 2017-10-23

### Added

- Alpha
9 changes: 0 additions & 9 deletions core/components/moddiscoursesso/docs/changelog.txt

This file was deleted.

27 changes: 27 additions & 0 deletions core/components/moddiscoursesso/docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# modDiscourseSSO

Single-Sign-On Extra for MODX Revolution that integrates the brilliant Discourse forums.

- Author: Murray Wood <[email protected]>
- License: GNU GPLv2

This extra requires MODX 2.3+ and PHP 5.5+. It still works with MODX 3.x, Discourse 3.x. and PHP 8.3.

## Instructions

- Download and install Discourse as shown here: https://blog.discourse.org/2014/04/install-discourse-in-under-30-minutes/
- Install this extra via the MODX package manager
- Set your discourse host name, your secret code (a long random string), and your scheme (http or https) for modDiscourseSSO in the MODX system settings.
- Create a resource called "Discourse" (or anything you like) and add the snippet ```[[!discourse? &loginPage=`<login_id>`]]``` to either the resource content field or directly to the template. `<login_id>` has to be replaced with the resource id of your MODX login page.
- If you haven't already, create a resource to contain your MODX login form. The resource id of this page should be entered into the &loginPage parameter of the discourse snippet call.
- Also create a resource that contains a logout snippet. For example you can use the one from the Login Extra.
- Fill out the SSO settings within Discourse as shown here: https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045
- The sso_secret should be the same as the one you added to MODX.
- The sso_url should be the full URL where your ```[[!discourse? &loginPage=`<login_id>`]]``` snippet call resides.
- Also set the "logout redirect" setting (under Users) should contain the full URL of your MODX logout snippet.
- The next time you load Discourse (while logged into MODX) you'll see your MODX account details showing up in Discourse.


## Snippet parameters

- ```&loginPage``` - This is the resource id of your MODX login page. Unauthorized users will be redirected to this page. If the parameter is not included with the snippet the value of the login_page system setting will be used instead. This param will also accept a URL in case the page you want to redirect to is outside of MODX.
29 changes: 0 additions & 29 deletions core/components/moddiscoursesso/docs/readme.txt

This file was deleted.

2 changes: 1 addition & 1 deletion core/components/moddiscoursesso/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Default English Lexicon Entries for modDiscourseSSO
* Default Lexicon Entries for modDiscourseSSO
*
* @package moddiscoursesso
* @subpackage lexicon
Expand Down
9 changes: 9 additions & 0 deletions core/components/moddiscoursesso/lexicon/en/properties.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Properties Lexicon Entries for modDiscourseSSO
*
* @package moddiscoursesso
* @subpackage lexicon
*/

$_lang['moddiscoursesso.discourse.loginPage'] = 'This is the resource ID of your MODX login page. Unauthorised users will be redirected to this page. If this parameter is not set, the value of the moddiscoursesso.login_page system setting will be used. This parameter uses a URL if the page you want to redirect to is outside of MODX.';
19 changes: 19 additions & 0 deletions core/components/moddiscoursesso/lexicon/en/setting.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Setting Lexicon Entries for modDiscourseSSO
*
* @package moddiscoursesso
* @subpackage lexicon
*/

$_lang['area_default'] = 'Default';
$_lang['setting_moddiscoursesso.host'] = 'Discourse Host Name';
$_lang['setting_moddiscoursesso.host_desc'] = 'The Discourse host name.';
$_lang['setting_moddiscoursesso.login_page'] = 'Login Page';
$_lang['setting_moddiscoursesso.login_page_desc'] = 'This is the resource ID of your MODX login page. Unauthorised users will be redirected to this page.';
$_lang['setting_moddiscoursesso.scheme'] = 'Discourse Url Scheme';
$_lang['setting_moddiscoursesso.scheme_desc'] = 'The Discourse url scheme.';
$_lang['setting_moddiscoursesso.secret'] = 'Discourse Secret Code';
$_lang['setting_moddiscoursesso.secret_desc'] = 'The Discourse secret code that is used to hash the SSO payloads.';
$_lang['setting_moddiscoursesso.sso_parameters'] = 'Additional SSO Parameters';
$_lang['setting_moddiscoursesso.sso_parameters_desc'] = 'JSON encoded array of additional SSO parameters.';
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,19 @@ public function authenticateUser($loginPage) {
'username' => $userUsername,
'name' => $userFullName
);
if ($this->modx->getOption('moddiscoursesso.sso_parameters', $this->options, '')) {
$ssoParameters = json_decode($this->modx->getOption('moddiscoursesso.sso_parameters', $this->options, ''), true);
if ($ssoParameters != null && is_array($ssoParameters)) {
foreach ($ssoParameters as $key => $value) {
$extraParameters[$key] = $value;
}
}
}

// build query string and redirect back to the Discourse site
$query = $this->ssoHelper->getSignInString($nonce, $userId, $userEmail, $extraParameters);
header('Location: '.$this->modx->getOption('moddiscoursesso.scheme').'://'.$this->modx->getOption('moddiscoursesso.host').'/session/sso_login?' . $query);
exit(0);

}
}
}