From f10952e92c1dd9a1a13064ebfae7802ec18bd0ff Mon Sep 17 00:00:00 2001 From: Daniel Kiesel Date: Wed, 1 Mar 2017 17:49:42 +0100 Subject: [PATCH 1/5] refactored for contao 4 --- .editorconfig | 26 +++ .gitignore | 11 ++ CraffftContaoDiscourseSSOBundle.php | 19 +++ DependencyInjection/Configuration.php | 34 ++++ .../CraffftContaoDiscourseSSOExtension.php | 50 ++++++ README.md | 47 ++++++ Resources/config/services.yml | 5 + Resources/contao/ModuleSSOProvider.php | 132 +++++++++++++++ .../contao}/config/config.php | 8 +- .../contao}/dca/tl_module.php | 6 +- .../contao}/dca/tl_settings.php | 47 +++--- .../contao}/languages/de/modules.php | 8 +- .../contao}/languages/de/tl_settings.php | 7 +- .../contao}/languages/en/modules.php | 8 +- .../contao}/languages/en/tl_settings.php | 7 +- SSO/SSOProviderPayload.php | 150 ++++++++++++++++++ .../plugins/Discourse/SSOProviderPayload.php | 141 ---------------- .../modules/discourse/ModuleSSOProvider.php | 131 --------------- composer.json | 40 +++++ 19 files changed, 551 insertions(+), 326 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 CraffftContaoDiscourseSSOBundle.php create mode 100644 DependencyInjection/Configuration.php create mode 100644 DependencyInjection/CraffftContaoDiscourseSSOExtension.php create mode 100644 README.md create mode 100644 Resources/config/services.yml create mode 100644 Resources/contao/ModuleSSOProvider.php rename {TL_ROOT/system/modules/discourse => Resources/contao}/config/config.php (87%) rename {TL_ROOT/system/modules/discourse => Resources/contao}/dca/tl_module.php (93%) rename {TL_ROOT/system/modules/discourse => Resources/contao}/dca/tl_settings.php (55%) rename {TL_ROOT/system/modules/discourse => Resources/contao}/languages/de/modules.php (94%) rename {TL_ROOT/system/modules/discourse => Resources/contao}/languages/de/tl_settings.php (94%) rename {TL_ROOT/system/modules/discourse => Resources/contao}/languages/en/modules.php (94%) rename {TL_ROOT/system/modules/discourse => Resources/contao}/languages/en/tl_settings.php (94%) create mode 100644 SSO/SSOProviderPayload.php delete mode 100644 TL_ROOT/plugins/Discourse/SSOProviderPayload.php delete mode 100644 TL_ROOT/system/modules/discourse/ModuleSSOProvider.php create mode 100644 composer.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5e1c513 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +# editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.py] +indent_size = 4 + +[*.yml] +indent_size = 4 + +[*.php] +indent_size = 4 + +[*.json] +indent_size = 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5cd487 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# IDE & OS +.idea/ +.DS_Store + +# Project +vendor +composer.phar +composer.lock +phpunit.xml +Tests/Controller/App/*/ +Tests/Controller/App/sqlite.db.cache diff --git a/CraffftContaoDiscourseSSOBundle.php b/CraffftContaoDiscourseSSOBundle.php new file mode 100644 index 0000000..6c0fd47 --- /dev/null +++ b/CraffftContaoDiscourseSSOBundle.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\ContaoDiscourseSSOBundle; + +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class CraffftContaoDiscourseSSOBundle extends Bundle +{ +} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php new file mode 100644 index 0000000..1245da4 --- /dev/null +++ b/DependencyInjection/Configuration.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\ContaoDiscourseSSOBundle\DependencyInjection; + +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; + +/** + * This is the class that validates and merges configuration from your app/config files + * + * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} + */ +class Configuration implements ConfigurationInterface +{ + /** + * {@inheritdoc} + */ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $treeBuilder->root('craffft_contao_discourse_sso'); + + return $treeBuilder; + } +} diff --git a/DependencyInjection/CraffftContaoDiscourseSSOExtension.php b/DependencyInjection/CraffftContaoDiscourseSSOExtension.php new file mode 100644 index 0000000..337f2df --- /dev/null +++ b/DependencyInjection/CraffftContaoDiscourseSSOExtension.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Craffft\ContaoDiscourseSSOBundle\DependencyInjection; + +use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\Loader; + +/** + * This is the class that loads and manages your bundle configuration + * + * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} + */ +class CraffftContaoDiscourseSSOExtension extends Extension +{ + /** + * {@inheritdoc} + */ + public function load(array $configs, ContainerBuilder $container) + { + $configuration = new Configuration(); + $config = $this->processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } + + /** + * Returns the recommended alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + */ + public function getAlias() + { + return 'craffft_contao_discourse_sso'; + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..38e9534 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +Contao Discourse SSO Bundle +============================= + +Contao Discourse SSO Bundle for Symfony + +Installation +------------ + +### Step 1: Download the Bundle + +Open a command console, enter your project directory and execute the +following command to download the latest stable version of this bundle: + +```bash +$ composer require craffft/contao-discourse "~2.0" +``` + +This command requires you to have Composer installed globally, as explained +in the [installation chapter](https://getcomposer.org/doc/00-intro.md) +of the Composer documentation. + +### Step 2: Enable the Bundle + +Then, enable the bundle by adding it to the list of registered bundles +in the `app/AppKernel.php` file of your project: + +```php + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * PHP version 5 + * @copyright Florian Bender 2015 + * @author Florian Bender + * @author Daniel Kiesel + * @package Discourse + * @license AGPLv3 (GNU Affero GPL v3.0) + * @filesource + */ + +namespace DiscourseSSO; + +use Contao\BackendTemplate; +use Contao\Module; +//use Craffft\ContaoDiscourseSSOBundle\SSO\SSOProviderPayload; + +/** + * Class ModuleSSOProvider + * + * Module to provide user authentication for Discourse instances against the + * user database of a Contao instance. + * @copyright Florian Bender 2015 + * @author Florian Bender + * @author Daniel Kiesel + * @package Discourse + */ +class ModuleSSOProvider extends Module +{ + /** + * Template + * @var string + */ + protected $strTemplate = ''; + + /** + * Validate the current user and redirect (if permissions allow). + * @return string + */ + public function generate() + { + // Show placeholder in Backend + if (TL_MODE == 'BE') { + $objTemplate = new BackendTemplate('be_wildcard'); + + $objTemplate->wildcard = '### DISCOURSE SSO PROVIDER MODULE ###'; + $objTemplate->title = $this->headline; + $objTemplate->id = $this->id; + $objTemplate->link = $this->name; + $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; + + return $objTemplate->parse(); + } +/* + // Return nothing if necessary parameters were not provided + if (!isset($_GET['sso']) || !isset($_GET['sig'])) { + return ''; // TODO: return error? log?? + } + + // FIX: use raw data instead of sanitized data from Contao Input class + $strSSOPayload = urldecode($_GET['sso']); + $strSSOSignature = $_GET['sig']; + + // TODO: Redirect to current URL (without sso/sig parameters) if user is not logged in or no payload was provided + if (!FE_USER_LOGGED_IN || empty($strSSOPayload) || empty($strSSOSignature)) { + return ''; + } + + $container = \System::getContainer(); + /** @var SSOProviderPayload $objSSOPayload * + $objSSOPayload = $container->get('craffft.sso.sso_provider_payload'); + $objSSOPayload->setSignatureSecret($GLOBALS['TL_CONFIG']['discourseSSOSecret']); + $objSSOPayload->parseChallengePayload($strSSOPayload, $strSSOSignature); // TODO: catch exception? + + $this->import('FrontendUser', 'User'); + + // TODO: add moderator group support + // optional values: 'username', (full) 'name', 'avatar_url', + // 'require_activation', 'custom.*' (custom fields), etc. + $arrParameters = array( + 'name' => $this->User->firstname . ' ' . $this->User->lastname, + // 'avatar_url' => $this->User->portrait, + // 'custom.xyz' => '', // see Discourse Plugins & Discourse, Admin, Customize, User Fields; https://meta.discourse.org/t/custom-user-fields-for-plugins/14956 + // 'admin' => 0, + 'moderator' => 0 + ); + // TODO: reduce amount of data being logged? + $this->log('User "' . $this->User->username . '" used SSO (' . json_encode($arrParameters) . ')', + get_class($this) . ' generate()', TL_ACCESS); + $arrResponseData = $objSSOPayload->getResponseDataForUser($this->User->id, $this->User->email, $arrParameters); + + // create redirect URL + $arrDiscourseHostParts = parse_url($GLOBALS['TL_CONFIG']['discourseSSOHost']); + + if ($arrDiscourseHostParts === false || !isset($arrDiscourseHostParts['scheme']) || !isset($arrDiscourseHostParts['host'])) { + throw new Exception("Invalid setting: 'discourseSSOHost' (must be a valid URL including protocol)"); + } + + $strDiscourseSSOEndpoint = $arrDiscourseHostParts['scheme'] . '://' . $arrDiscourseHostParts['host']; + $strDiscourseSSOEndpoint .= $objSSOPayload::API_ENDPOINT; + $strDiscourseSSOEndpoint .= '?' . http_build_query($arrResponseData); + + $this->redirect($strDiscourseSSOEndpoint); + + return '';*/ + } + + /** + * Generate the module + */ + protected function compile() + { + return; + } +} diff --git a/TL_ROOT/system/modules/discourse/config/config.php b/Resources/contao/config/config.php similarity index 87% rename from TL_ROOT/system/modules/discourse/config/config.php rename to Resources/contao/config/config.php index db19c5a..53a5847 100644 --- a/TL_ROOT/system/modules/discourse/config/config.php +++ b/Resources/contao/config/config.php @@ -1,4 +1,4 @@ - + * @author Daniel Kiesel * @package Discourse * @license AGPLv3 (GNU Affero GPL v3.0) * @filesource @@ -31,7 +32,4 @@ * FRONT END MODULES * ------------------------------------------------------------------------- */ -$GLOBALS['FE_MOD']['application']['discourseSSOProvider'] = 'ModuleSSOProvider'; - - - #EOF +$GLOBALS['FE_MOD']['application']['discourseSSOProvider'] = '\DiscourseSSO\ModuleSSOProvider'; diff --git a/TL_ROOT/system/modules/discourse/dca/tl_module.php b/Resources/contao/dca/tl_module.php similarity index 93% rename from TL_ROOT/system/modules/discourse/dca/tl_module.php rename to Resources/contao/dca/tl_module.php index 48b640c..232ed81 100644 --- a/TL_ROOT/system/modules/discourse/dca/tl_module.php +++ b/Resources/contao/dca/tl_module.php @@ -1,4 +1,4 @@ - + * @author Daniel Kiesel * @package Discourse * @license AGPLv3 (GNU Affero GPL v3.0) * @filesource */ $GLOBALS['TL_DCA']['tl_module']['palettes']['discourseSSOProvider'] = '{title_legend},name;{protected_legend},protected;{expert_legend:hide},guests,cssID'; - - -#EOF diff --git a/TL_ROOT/system/modules/discourse/dca/tl_settings.php b/Resources/contao/dca/tl_settings.php similarity index 55% rename from TL_ROOT/system/modules/discourse/dca/tl_settings.php rename to Resources/contao/dca/tl_settings.php index b58a7b4..287437c 100644 --- a/TL_ROOT/system/modules/discourse/dca/tl_settings.php +++ b/Resources/contao/dca/tl_settings.php @@ -1,4 +1,4 @@ - + * @author Daniel Kiesel * @package Discourse * @license AGPLv3 (GNU Affero GPL v3.0) * @filesource @@ -32,33 +33,33 @@ $GLOBALS['TL_DCA']['tl_settings']['fields']['discourseSSOHost'] = array ( - 'label' => &$GLOBALS['TL_LANG']['tl_settings']['discourseSSOHost'], - 'exclude' => true, - 'inputType' => 'text', - 'eval' => array('rgxp'=>'url', 'decodeEntities'=>true, 'tl_class'=>'w50'), - 'save_callback' => array( - array('tl_settings_discourse', 'validateURL') - ) + 'label' => &$GLOBALS['TL_LANG']['tl_settings']['discourseSSOHost'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('rgxp'=>'url', 'decodeEntities'=>true, 'tl_class'=>'w50'), + 'save_callback' => array( + array('tl_settings_discourse', 'validateURL') + ) ); $GLOBALS['TL_DCA']['tl_settings']['fields']['discourseSSOSecret'] = array ( - 'label' => &$GLOBALS['TL_LANG']['tl_settings']['discourseSSOSecret'], - 'exclude' => true, - 'inputType' => 'text', - 'eval' => array('decodeEntities'=>false, 'tl_class'=>'w50') + 'label' => &$GLOBALS['TL_LANG']['tl_settings']['discourseSSOSecret'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('decodeEntities'=>false, 'tl_class'=>'w50') ); -class tl_settings_discourse extends tl_settings { - public function validateURL($varValue) { - $varValue = $this->idnaEncodeUrl($varValue); // method of System class - if (filter_var($varValue, FILTER_VALIDATE_URL) === false) { - throw new Exception('Not a valid URL: ' + $varValue); - } - return $varValue; - } -} - +class tl_settings_discourse extends tl_settings +{ + public function validateURL($varValue) + { + $varValue = $this->idnaEncodeUrl($varValue); // method of System class + if (filter_var($varValue, FILTER_VALIDATE_URL) === false) { + throw new Exception('Not a valid URL: ' + $varValue); + } -#EOF + return $varValue; + } +} diff --git a/TL_ROOT/system/modules/discourse/languages/de/modules.php b/Resources/contao/languages/de/modules.php similarity index 94% rename from TL_ROOT/system/modules/discourse/languages/de/modules.php rename to Resources/contao/languages/de/modules.php index 7a97be2..6d334db 100644 --- a/TL_ROOT/system/modules/discourse/languages/de/modules.php +++ b/Resources/contao/languages/de/modules.php @@ -1,4 +1,4 @@ - + * @author Daniel Kiesel * @package Discourse * @license LGPL * @filesource */ - /** * Extension folder */ $GLOBALS['TL_LANG']['MOD']['discourse'] = array('Discourse-Anbindung'); - /** * Front end modules */ $GLOBALS['TL_LANG']['FMD']['discourseSSOProvider'] = array('Discourse SSO Provider', 'Dieses Modul ermöglicht einen Single Sign-On von einer Discourse-Installation. Nach erfolgreicher Authentisierung wir der Nutzer auf den Discourse Host (s. Contao Einstellungen) weitergleitet. Das Modul erzeugt keine Ausgabe (ähnlich dem "Logout"-Modul).'); - - -#EOF diff --git a/TL_ROOT/system/modules/discourse/languages/de/tl_settings.php b/Resources/contao/languages/de/tl_settings.php similarity index 94% rename from TL_ROOT/system/modules/discourse/languages/de/tl_settings.php rename to Resources/contao/languages/de/tl_settings.php index 76cbfa7..9e10cc8 100644 --- a/TL_ROOT/system/modules/discourse/languages/de/tl_settings.php +++ b/Resources/contao/languages/de/tl_settings.php @@ -1,4 +1,4 @@ - + * @author Daniel Kiesel * @package Discourse * @license LGPL * @filesource */ - /** * Fields */ @@ -37,6 +37,3 @@ * Legends */ $GLOBALS['TL_LANG']['tl_settings']['discourse_legend'] = 'Discourse Einstellungen'; - - -#EOF diff --git a/TL_ROOT/system/modules/discourse/languages/en/modules.php b/Resources/contao/languages/en/modules.php similarity index 94% rename from TL_ROOT/system/modules/discourse/languages/en/modules.php rename to Resources/contao/languages/en/modules.php index c4977eb..37c65bc 100644 --- a/TL_ROOT/system/modules/discourse/languages/en/modules.php +++ b/Resources/contao/languages/en/modules.php @@ -1,4 +1,4 @@ - + * @author Daniel Kiesel * @package Discourse * @license LGPL * @filesource */ - /** * Extension folder */ $GLOBALS['TL_LANG']['MOD']['discourse'] = array('Discourse Connector'); - /** * Front end modules */ $GLOBALS['TL_LANG']['FMD']['discourseSSOProvider'] = array('Discourse SSO Provider', 'This module enables Single Sign-On of a Discourse installation. Users will be redirected to the Discourse Host (see Contao Settings) after successful authentication. This module does not produce any output (similar to the "Logout" module).'); - - -#EOF diff --git a/TL_ROOT/system/modules/discourse/languages/en/tl_settings.php b/Resources/contao/languages/en/tl_settings.php similarity index 94% rename from TL_ROOT/system/modules/discourse/languages/en/tl_settings.php rename to Resources/contao/languages/en/tl_settings.php index ff0a443..2ecca89 100644 --- a/TL_ROOT/system/modules/discourse/languages/en/tl_settings.php +++ b/Resources/contao/languages/en/tl_settings.php @@ -1,4 +1,4 @@ - + * @author Daniel Kiesel * @package Discourse * @license LGPL * @filesource */ - /** * Fields */ @@ -37,6 +37,3 @@ * Legends */ $GLOBALS['TL_LANG']['tl_settings']['discourse_legend'] = 'Discourse settings'; - - -#EOF diff --git a/SSO/SSOProviderPayload.php b/SSO/SSOProviderPayload.php new file mode 100644 index 0000000..5ede5a0 --- /dev/null +++ b/SSO/SSOProviderPayload.php @@ -0,0 +1,150 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * PHP version 5 + * @copyright Florian Bender 2015 + * @author Florian Bender + * @package Discourse + * @license AGPLv3 (GNU Affero GPL v3.0) + * @filesource + */ +// based on github.com/cviebrock/discourse-php +// @see https://raw.githubusercontent.com/cviebrock/discourse-php/master/src/SSOHelper.php +// @license (TBD) + +namespace Craffft\ContaoDiscourseSSOBundle\SSO; + +class SSOProviderPayload +{ + /** + * Endpoint which receives SSO response; add host and query like this: + * http://discourse_site.tld{API_ENDPOINT}?sso={PAYLOAD}&sig={SIG} + * @var string + */ + const API_ENDPOINT = '/session/sso_login'; + + /** + * Secret used for signing payload data + * @var string + */ + private $strSignatureSecret = ''; + + /** + * Nonce retrieved from challenge payload + * @var string + */ + protected $strPayloadNonce = ''; + + /** + * Set signature secret + * @param string $strSecret Shared secret used for the payload signature + */ + public function setSignatureSecret(string $strSecret) + { + $this->strSignatureSecret = $strSecret; + } + + /** + * Check signature (and thus integrity) of payload + * @return boolean + */ + public function isPayloadValid($strPayload, $strSignature) + { + return ($this->getPayloadSignature($strPayload) === $strSignature); + } + + /** + * Validate and parse payload as well as retrieve and store nonce + * @param string $strPayload Challenge payload (must be urldecode()d!) + * @param string $strSignature The payload's signature + * @return true + * @throws \Exception + */ + public function parseChallengePayload($strPayload, $strSignature) + { + if (!$this->isPayloadValid($strPayload, $strSignature)) { + throw new \Exception('Payload could not be validated against signature (Payload: "' . $strPayload . '", Signature: "' . $strSignature . '")'); + } + // parse payload + $arrPayloadData = array(); + parse_str(base64_decode($strPayload), $arrPayloadData); + // retrieve nonce + if (!array_key_exists('nonce', $arrPayloadData)) { + throw new \Exception('Invalid payload: Nonce not found'); + } + $this->strPayloadNonce = $arrPayloadData['nonce']; + + return true; + } + + /** + * Generate and return response payload with signature ready for http_build_query() + * @see self::generateResponsePayload + * @param string $strUserId (External) user ID + * @param string $strUserEmail E-mail address of user + * @param array $arrOptionalParameters More parameters to include in payload + * @todo Use func_get_args resp. http://php.net/manual/functions.arguments.html#functions.variable-arg-list + */ + public function getResponseDataForUser($strUserId, $strUserEmail, $arrOptionalParameters = array()) + { + $arrPayloadData = array( + // 'nonce' => $this->strPayloadNonce, + 'external_id' => $strUserId, + 'email' => $strUserEmail + ); + $arrPayloadData = array_merge($arrPayloadData, $arrOptionalParameters); + $strPayload = $this->generateResponsePayload($arrPayloadData); + + return array( + 'sso' => $strPayload, + 'sig' => $this->getPayloadSignature($strPayload) + ); + } + + /** + * Generate and return response payload using nonce from challenge payload + * @param array $arrPayloadParameters Parameters to include in payload + * @return string + * @todo Check input array for required / valid values? + * @todo Consider making this protected + */ + public function generateResponsePayload($arrPayloadParameters) + { + // $arrPayloadParameters required values: nonce, email, external_id + // … optional values: 'username', (full) 'name', 'avatar_url', + // 'require_activation', 'custom.*' (custom fields), etc. + // augment payload data with nonce + $arrPayloadParameters['nonce'] = $this->strPayloadNonce; + + // create & return payload string + return base64_encode(http_build_query($arrPayloadParameters)); + } + + /** + * Return signature of payload using secret + * @param string $strPayload + * @return string + * @todo Consider making this protected + */ + public function getPayloadSignature($strPayload) + { + return hash_hmac('sha256', $strPayload, $this->strSignatureSecret); + } + +} diff --git a/TL_ROOT/plugins/Discourse/SSOProviderPayload.php b/TL_ROOT/plugins/Discourse/SSOProviderPayload.php deleted file mode 100644 index 4c65aa8..0000000 --- a/TL_ROOT/plugins/Discourse/SSOProviderPayload.php +++ /dev/null @@ -1,141 +0,0 @@ - - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @package Discourse - * @license AGPLv3 (GNU Affero GPL v3.0) - * @filesource - */ -// based on github.com/cviebrock/discourse-php -// @see https://raw.githubusercontent.com/cviebrock/discourse-php/master/src/SSOHelper.php -// @license (TBD) - -class SSOProviderPayload { - - /** - * Endpoint which receives SSO response; add host and query like this: - * http://discourse_site.tld{API_ENDPOINT}?sso={PAYLOAD}&sig={SIG} - * @var string - */ - const API_ENDPOINT = '/session/sso_login'; - - /** - * Secret used for signing payload data - * @var string - */ - private $strSignatureSecret = ''; - - /** - * Nonce retrieved from challenge payload - * @var string - */ - protected $strPayloadNonce = ''; - - /** - * Initalize the object and set signature secret - * @param string $strSecret Shared secret used for the payload signature - */ - public function __construct($strSecret) { - $this->strSignatureSecret = $strSecret; - } - - /** - * Check signature (and thus integrity) of payload - * @return boolean - */ - public function isPayloadValid($strPayload, $strSignature) { - return ($this->getPayloadSignature($strPayload) === $strSignature); - } - - /** - * Validate and parse payload as well as retrieve and store nonce - * @param string $strPayload Challenge payload (must be urldecode()d!) - * @param string $strSignature The payload's signature - * @return true - * @throws \Exception - */ - public function parseChallengePayload($strPayload, $strSignature) { - if (!$this->isPayloadValid($strPayload, $strSignature)) { - throw new \Exception('Payload could not be validated against signature (Payload: "'.$strPayload.'", Signature: "'.$strSignature.'")'); - } - // parse payload - $arrPayloadData = array(); - parse_str(base64_decode($strPayload), $arrPayloadData); - // retrieve nonce - if (!array_key_exists('nonce', $arrPayloadData)) { - throw new \Exception('Invalid payload: Nonce not found'); - } - $this->strPayloadNonce = $arrPayloadData['nonce']; - return true; - } - - /** - * Generate and return response payload with signature ready for http_build_query() - * @see self::generateResponsePayload - * @param string $strUserId (External) user ID - * @param string $strUserEmail E-mail address of user - * @param array $arrOptionalParameters More parameters to include in payload - * @todo Use func_get_args resp. http://php.net/manual/functions.arguments.html#functions.variable-arg-list - */ - public function getResponseDataForUser($strUserId, $strUserEmail, $arrOptionalParameters = array()) { - $arrPayloadData = array( - // 'nonce' => $this->strPayloadNonce, - 'external_id' => $strUserId, - 'email' => $strUserEmail - ); - $arrPayloadData = array_merge($arrPayloadData, $arrOptionalParameters); - $strPayload = $this->generateResponsePayload($arrPayloadData); - return array( - 'sso' => $strPayload, - 'sig' => $this->getPayloadSignature($strPayload) - ); - } - - /** - * Generate and return response payload using nonce from challenge payload - * @param array $arrPayloadParameters Parameters to include in payload - * @return string - * @todo Check input array for required / valid values? - * @todo Consider making this protected - */ - public function generateResponsePayload($arrPayloadParameters) { - // $arrPayloadParameters required values: nonce, email, external_id - // … optional values: 'username', (full) 'name', 'avatar_url', - // 'require_activation', 'custom.*' (custom fields), etc. - // augment payload data with nonce - $arrPayloadParameters['nonce'] = $this->strPayloadNonce; - // create & return payload string - return base64_encode(http_build_query($arrPayloadParameters)); - } - - /** - * Return signature of payload using secret - * @param string $strPayload - * @return string - * @todo Consider making this protected - */ - public function getPayloadSignature($strPayload) { - return hash_hmac('sha256', $strPayload, $this->strSignatureSecret); - } - -} diff --git a/TL_ROOT/system/modules/discourse/ModuleSSOProvider.php b/TL_ROOT/system/modules/discourse/ModuleSSOProvider.php deleted file mode 100644 index 6c62095..0000000 --- a/TL_ROOT/system/modules/discourse/ModuleSSOProvider.php +++ /dev/null @@ -1,131 +0,0 @@ - - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @package Discourse - * @license AGPLv3 (GNU Affero GPL v3.0) - * @filesource - */ - - -require_once(TL_ROOT . '/plugins/Discourse/SSOProviderPayload.php'); - -/** - * Class ModuleSSOProvider - * - * Module to provide user authentication for Discourse instances against the - * user database of a Contao instance. - * @copyright Florian Bender 2015 - * @author Florian Bender - * @package Discourse - */ -class ModuleSSOProvider extends Module -{ - - /** - * Template - * @var string - */ - protected $strTemplate; - - - /** - * Validate the current user and redirect (if permissions allow). - * @return string - */ - public function generate() - { - - // Show placeholder in Backend - if (TL_MODE == 'BE') - { - $objTemplate = new BackendTemplate('be_wildcard'); - - $objTemplate->wildcard = '### DISCOURSE SSO PROVIDER MODULE ###'; - $objTemplate->title = $this->headline; - $objTemplate->id = $this->id; - $objTemplate->link = $this->name; - $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; - - return $objTemplate->parse(); - } - - // Return nothing if necessary parameters were not provided - if (!isset($_GET['sso']) || !isset($_GET['sig'])) { - return ''; // TODO: return error? log?? - } - - // FIX: use raw data instead of sanitized data from Contao Input class - $strSSOPayload = urldecode($_GET['sso']); - $strSSOSignature = $_GET['sig']; - - // TODO: Redirect to current URL (without sso/sig parameters) if user is not logged in or no payload was provided - if (!FE_USER_LOGGED_IN || empty($strSSOPayload) || empty($strSSOSignature)) { - return ''; - } - - $objSSOPayload = new \fbender\Discourse\SSOProviderPayload($GLOBALS['TL_CONFIG']['discourseSSOSecret']); - $objSSOPayload->parseChallengePayload($strSSOPayload, $strSSOSignature); // TODO: catch exception? - - $this->import('FrontendUser', 'User'); - - // TODO: add moderator group support - // optional values: 'username', (full) 'name', 'avatar_url', - // 'require_activation', 'custom.*' (custom fields), etc. - $arrParameters = array( - 'name' => $this->User->firstname.' '.$this->User->lastname, - // 'avatar_url' => $this->User->portrait, - // 'custom.xyz' => '', // see Discourse Plugins & Discourse, Admin, Customize, User Fields; https://meta.discourse.org/t/custom-user-fields-for-plugins/14956 - // 'admin' => 0, - 'moderator' => 0 - ); - // TODO: reduce amount of data being logged? - $this->log('User "' . $this->User->username . '" used SSO ('.json_encode($arrParameters).')', get_class($this) . ' generate()', TL_ACCESS); - $arrResponseData = $objSSOPayload->getResponseDataForUser($this->User->id, $this->User->email, $arrParameters); - - // create redirect URL - $arrDiscourseHostParts = parse_url($GLOBALS['TL_CONFIG']['discourseSSOHost']); - - if ($arrDiscourseHostParts === false || !isset($arrDiscourseHostParts['scheme']) || !isset($arrDiscourseHostParts['host'])) { - throw new Exception("Invalid setting: 'discourseSSOHost' (must be a valid URL including protocol)"); - } - - $strDiscourseSSOEndpoint = $arrDiscourseHostParts['scheme'] . '://' . $arrDiscourseHostParts['host']; - $strDiscourseSSOEndpoint .= $objSSOPayload::API_ENDPOINT; - $strDiscourseSSOEndpoint .= '?' . http_build_query($arrResponseData); - - $this->redirect($strDiscourseSSOEndpoint); - - return ''; - } - - /** - * Generate module - */ - protected function compile() - { - return; - } - -} - - -#EOF diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d99051c --- /dev/null +++ b/composer.json @@ -0,0 +1,40 @@ +{ + "name": "craffft/contao-discourse", + "type": "symfony-bundle", + "description": "ContaoDiscourseSSOBundle for Symfony with Contao", + "keywords": [ + "discourse", + "SSO", + "authentication" + ], + "license": "MIT", + "authors": [ + { + "name": "Florian Bender", + "email": "fb+git@quantumedia.de" + }, + { + "name": "Daniel Kiesel", + "homepage": "https://github.com/iCodr8" + } + ], + "support": { + "issues": "https://github.com/Craffft/contao-discourse/issues", + "source": "https://github.com/Craffft/contao-discourse" + }, + "require": { + "php": ">=7.0", + "symfony/framework-bundle": "~2.8|~3.0", + "symfony/http-kernel": "~2.8|~3.0" + }, + "autoload": { + "psr-4": { + "Craffft\\ContaoDiscourseSSOBundle\\": "" + } + }, + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + } +} From 56bf48f7f3205f75bc9c2142a12291a421aa1f90 Mon Sep 17 00:00:00 2001 From: Daniel Kiesel Date: Wed, 1 Mar 2017 20:08:43 +0100 Subject: [PATCH 2/5] refactored for contao 4 --- .../ModuleSSOProvider.php | 37 +++++-------------- Resources/contao/config/autoload.ini | 14 +++++++ Resources/contao/config/config.php | 36 ++++-------------- Resources/contao/dca/tl_module.php | 28 +++----------- Resources/contao/dca/tl_settings.php | 31 +++------------- Resources/contao/languages/de/modules.php | 29 +++------------ Resources/contao/languages/de/tl_settings.php | 29 +++------------ Resources/contao/languages/en/modules.php | 29 +++------------ Resources/contao/languages/en/tl_settings.php | 29 +++------------ SSO/SSOProviderPayload.php | 28 ++++---------- 10 files changed, 74 insertions(+), 216 deletions(-) rename {Resources/contao => FrontendModule}/ModuleSSOProvider.php (76%) create mode 100644 Resources/contao/config/autoload.ini diff --git a/Resources/contao/ModuleSSOProvider.php b/FrontendModule/ModuleSSOProvider.php similarity index 76% rename from Resources/contao/ModuleSSOProvider.php rename to FrontendModule/ModuleSSOProvider.php index e511bfc..07b5f18 100644 --- a/Resources/contao/ModuleSSOProvider.php +++ b/FrontendModule/ModuleSSOProvider.php @@ -1,36 +1,19 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. +/* + * This file is part of the Craffft Discourse SSO Bundle. * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * (c) Florian Bender + * (c) Daniel Kiesel * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @author Daniel Kiesel - * @package Discourse - * @license AGPLv3 (GNU Affero GPL v3.0) - * @filesource + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ -namespace DiscourseSSO; +namespace Craffft\ContaoDiscourseSSOBundle\FrontendModule; use Contao\BackendTemplate; use Contao\Module; -//use Craffft\ContaoDiscourseSSOBundle\SSO\SSOProviderPayload; /** * Class ModuleSSOProvider @@ -68,7 +51,7 @@ public function generate() return $objTemplate->parse(); } -/* + // Return nothing if necessary parameters were not provided if (!isset($_GET['sso']) || !isset($_GET['sig'])) { return ''; // TODO: return error? log?? @@ -84,7 +67,7 @@ public function generate() } $container = \System::getContainer(); - /** @var SSOProviderPayload $objSSOPayload * + /** @var SSOProviderPayload $objSSOPayload */ $objSSOPayload = $container->get('craffft.sso.sso_provider_payload'); $objSSOPayload->setSignatureSecret($GLOBALS['TL_CONFIG']['discourseSSOSecret']); $objSSOPayload->parseChallengePayload($strSSOPayload, $strSSOSignature); // TODO: catch exception? @@ -119,7 +102,7 @@ public function generate() $this->redirect($strDiscourseSSOEndpoint); - return '';*/ + return ''; } /** diff --git a/Resources/contao/config/autoload.ini b/Resources/contao/config/autoload.ini new file mode 100644 index 0000000..dd4f5c8 --- /dev/null +++ b/Resources/contao/config/autoload.ini @@ -0,0 +1,14 @@ +;; +; Configure what you want the autoload creator to register +;; +register_namespaces = false +register_classes = false +register_templates = false + +;; +; Override the default configuration for certain sub directories +;; +[vendor/*] +register_namespaces = false +register_classes = false +register_templates = false diff --git a/Resources/contao/config/config.php b/Resources/contao/config/config.php index 53a5847..950cda0 100644 --- a/Resources/contao/config/config.php +++ b/Resources/contao/config/config.php @@ -1,35 +1,13 @@ +/* + * This file is part of the Craffft Discourse SSO Bundle. * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * (c) Florian Bender + * (c) Daniel Kiesel * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @author Daniel Kiesel - * @package Discourse - * @license AGPLv3 (GNU Affero GPL v3.0) - * @filesource + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ - -/** - * ------------------------------------------------------------------------- - * FRONT END MODULES - * ------------------------------------------------------------------------- - */ -$GLOBALS['FE_MOD']['application']['discourseSSOProvider'] = '\DiscourseSSO\ModuleSSOProvider'; +$GLOBALS['FE_MOD']['application']['discourseSSOProvider'] = '\\Craffft\\ContaoDiscourseSSOBundle\\FrontendModule'; diff --git a/Resources/contao/dca/tl_module.php b/Resources/contao/dca/tl_module.php index 232ed81..209bc93 100644 --- a/Resources/contao/dca/tl_module.php +++ b/Resources/contao/dca/tl_module.php @@ -1,29 +1,13 @@ +/* + * This file is part of the Craffft Discourse SSO Bundle. * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * (c) Florian Bender + * (c) Daniel Kiesel * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @author Daniel Kiesel - * @package Discourse - * @license AGPLv3 (GNU Affero GPL v3.0) - * @filesource + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ $GLOBALS['TL_DCA']['tl_module']['palettes']['discourseSSOProvider'] = '{title_legend},name;{protected_legend},protected;{expert_legend:hide},guests,cssID'; diff --git a/Resources/contao/dca/tl_settings.php b/Resources/contao/dca/tl_settings.php index 287437c..16f7688 100644 --- a/Resources/contao/dca/tl_settings.php +++ b/Resources/contao/dca/tl_settings.php @@ -1,34 +1,15 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. +/* + * This file is part of the Craffft Discourse SSO Bundle. * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * (c) Florian Bender + * (c) Daniel Kiesel * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @author Daniel Kiesel - * @package Discourse - * @license AGPLv3 (GNU Affero GPL v3.0) - * @filesource + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ -/* - * dca: tl_settings - */ $GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] .= ';{discourse_legend},discourseSSOHost,discourseSSOSecret'; $GLOBALS['TL_DCA']['tl_settings']['fields']['discourseSSOHost'] = array diff --git a/Resources/contao/languages/de/modules.php b/Resources/contao/languages/de/modules.php index 6d334db..ee46557 100644 --- a/Resources/contao/languages/de/modules.php +++ b/Resources/contao/languages/de/modules.php @@ -1,30 +1,13 @@ - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. +/* + * This file is part of the Craffft Discourse SSO Bundle. * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. If not, please visit the Free - * Software Foundation website at . + * (c) Florian Bender + * (c) Daniel Kiesel * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @author Daniel Kiesel - * @package Discourse - * @license LGPL - * @filesource + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ /** diff --git a/Resources/contao/languages/de/tl_settings.php b/Resources/contao/languages/de/tl_settings.php index 9e10cc8..b116832 100644 --- a/Resources/contao/languages/de/tl_settings.php +++ b/Resources/contao/languages/de/tl_settings.php @@ -1,30 +1,13 @@ - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. +/* + * This file is part of the Craffft Discourse SSO Bundle. * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. If not, please visit the Free - * Software Foundation website at . + * (c) Florian Bender + * (c) Daniel Kiesel * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @author Daniel Kiesel - * @package Discourse - * @license LGPL - * @filesource + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ /** diff --git a/Resources/contao/languages/en/modules.php b/Resources/contao/languages/en/modules.php index 37c65bc..3989fa3 100644 --- a/Resources/contao/languages/en/modules.php +++ b/Resources/contao/languages/en/modules.php @@ -1,30 +1,13 @@ - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. +/* + * This file is part of the Craffft Discourse SSO Bundle. * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. If not, please visit the Free - * Software Foundation website at . + * (c) Florian Bender + * (c) Daniel Kiesel * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @author Daniel Kiesel - * @package Discourse - * @license LGPL - * @filesource + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ /** diff --git a/Resources/contao/languages/en/tl_settings.php b/Resources/contao/languages/en/tl_settings.php index 2ecca89..3ae4403 100644 --- a/Resources/contao/languages/en/tl_settings.php +++ b/Resources/contao/languages/en/tl_settings.php @@ -1,30 +1,13 @@ - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. +/* + * This file is part of the Craffft Discourse SSO Bundle. * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. If not, please visit the Free - * Software Foundation website at . + * (c) Florian Bender + * (c) Daniel Kiesel * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @author Daniel Kiesel - * @package Discourse - * @license LGPL - * @filesource + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ /** diff --git a/SSO/SSOProviderPayload.php b/SSO/SSOProviderPayload.php index 5ede5a0..5707bc6 100644 --- a/SSO/SSOProviderPayload.php +++ b/SSO/SSOProviderPayload.php @@ -1,29 +1,15 @@ +/* + * This file is part of the Craffft Discourse SSO Bundle. * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * (c) Florian Bender + * (c) Daniel Kiesel * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * PHP version 5 - * @copyright Florian Bender 2015 - * @author Florian Bender - * @package Discourse - * @license AGPLv3 (GNU Affero GPL v3.0) - * @filesource + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ + // based on github.com/cviebrock/discourse-php // @see https://raw.githubusercontent.com/cviebrock/discourse-php/master/src/SSOHelper.php // @license (TBD) From 741104a656cc85a64a193065f0db2888845e1c05 Mon Sep 17 00:00:00 2001 From: Daniel Kiesel Date: Wed, 1 Mar 2017 20:12:21 +0100 Subject: [PATCH 3/5] refactored for contao 4 --- Resources/contao/config/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/contao/config/config.php b/Resources/contao/config/config.php index 950cda0..5ad6e4c 100644 --- a/Resources/contao/config/config.php +++ b/Resources/contao/config/config.php @@ -10,4 +10,4 @@ * file that was distributed with this source code. */ -$GLOBALS['FE_MOD']['application']['discourseSSOProvider'] = '\\Craffft\\ContaoDiscourseSSOBundle\\FrontendModule'; +$GLOBALS['FE_MOD']['application']['discourseSSOProvider'] = '\\Craffft\\ContaoDiscourseSSOBundle\\FrontendModule\\ModuleSSOProvider'; From 1e6ef7732866a8fe4051ca2f5752c5d3b9ef5fa9 Mon Sep 17 00:00:00 2001 From: Daniel Kiesel Date: Wed, 1 Mar 2017 20:26:38 +0100 Subject: [PATCH 4/5] fixed some bugs --- Resources/contao/dca/tl_module.php | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/contao/dca/tl_module.php b/Resources/contao/dca/tl_module.php index 209bc93..6e9752f 100644 --- a/Resources/contao/dca/tl_module.php +++ b/Resources/contao/dca/tl_module.php @@ -10,4 +10,4 @@ * file that was distributed with this source code. */ -$GLOBALS['TL_DCA']['tl_module']['palettes']['discourseSSOProvider'] = '{title_legend},name;{protected_legend},protected;{expert_legend:hide},guests,cssID'; +$GLOBALS['TL_DCA']['tl_module']['palettes']['discourseSSOProvider'] = '{title_legend},name,type;{protected_legend},protected;{expert_legend:hide},guests,cssID'; diff --git a/composer.json b/composer.json index d99051c..bc632a8 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "source": "https://github.com/Craffft/contao-discourse" }, "require": { - "php": ">=7.0", + "php": ">=7.0.0", "symfony/framework-bundle": "~2.8|~3.0", "symfony/http-kernel": "~2.8|~3.0" }, From 576c0f876a15f2016027b6c7885d56879d0cd41e Mon Sep 17 00:00:00 2001 From: Daniel Kiesel Date: Sat, 2 Mar 2019 13:51:42 +0100 Subject: [PATCH 5/5] added Contao Manager --- composer.json | 18 +++++------ src/ContaoManager/Plugin.php | 32 +++++++++++++++++++ .../CraffftContaoDiscourseSSOBundle.php | 0 .../DependencyInjection}/Configuration.php | 0 .../CraffftContaoDiscourseSSOExtension.php | 0 .../FrontendModule}/ModuleSSOProvider.php | 0 .../Resources}/config/services.yml | 0 .../Resources}/contao/config/autoload.ini | 0 .../Resources}/contao/config/config.php | 0 .../Resources}/contao/dca/tl_module.php | 0 .../Resources}/contao/dca/tl_settings.php | 0 .../contao/languages/de/modules.php | 0 .../contao/languages/de/tl_settings.php | 0 .../contao/languages/en/modules.php | 0 .../contao/languages/en/tl_settings.php | 0 {SSO => src/SSO}/SSOProviderPayload.php | 0 16 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/ContaoManager/Plugin.php rename CraffftContaoDiscourseSSOBundle.php => src/CraffftContaoDiscourseSSOBundle.php (100%) rename {DependencyInjection => src/DependencyInjection}/Configuration.php (100%) rename {DependencyInjection => src/DependencyInjection}/CraffftContaoDiscourseSSOExtension.php (100%) rename {FrontendModule => src/FrontendModule}/ModuleSSOProvider.php (100%) rename {Resources => src/Resources}/config/services.yml (100%) rename {Resources => src/Resources}/contao/config/autoload.ini (100%) rename {Resources => src/Resources}/contao/config/config.php (100%) rename {Resources => src/Resources}/contao/dca/tl_module.php (100%) rename {Resources => src/Resources}/contao/dca/tl_settings.php (100%) rename {Resources => src/Resources}/contao/languages/de/modules.php (100%) rename {Resources => src/Resources}/contao/languages/de/tl_settings.php (100%) rename {Resources => src/Resources}/contao/languages/en/modules.php (100%) rename {Resources => src/Resources}/contao/languages/en/tl_settings.php (100%) rename {SSO => src/SSO}/SSOProviderPayload.php (100%) diff --git a/composer.json b/composer.json index bc632a8..4685f3a 100644 --- a/composer.json +++ b/composer.json @@ -23,18 +23,18 @@ "source": "https://github.com/Craffft/contao-discourse" }, "require": { - "php": ">=7.0.0", - "symfony/framework-bundle": "~2.8|~3.0", - "symfony/http-kernel": "~2.8|~3.0" + "php": ">=7.1", + "contao/core-bundle": "~4.4" }, - "autoload": { - "psr-4": { - "Craffft\\ContaoDiscourseSSOBundle\\": "" - } + "require-dev": { + "contao/manager-plugin": "^2.0" }, "extra": { - "branch-alias": { - "dev-master": "2.x-dev" + "contao-manager-plugin": "Craffft\\ContaoDiscourseSSOBundle\\ContaoManager\\Plugin" + }, + "autoload": { + "psr-4": { + "Craffft\\ContaoDiscourseSSOBundle\\": "src/" } } } diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php new file mode 100644 index 0000000..84d5dab --- /dev/null +++ b/src/ContaoManager/Plugin.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Craffft\ContaoDiscourseSSOBundle\ContaoManager; + +use Contao\CoreBundle\ContaoCoreBundle; +use Contao\ManagerPlugin\Bundle\BundlePluginInterface; +use Contao\ManagerPlugin\Bundle\Config\BundleConfig; +use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; +use Craffft\ContaoDiscourseSSOBundle\CraffftContaoDiscourseSSOBundle; + +class Plugin implements BundlePluginInterface +{ + public function getBundles(ParserInterface $parser) + { + return [ + BundleConfig::create(CraffftContaoDiscourseSSOBundle::class) + ->setLoadAfter([ContaoCoreBundle::class]) + ->setReplace(['discourse-sso']), + ]; + } +} diff --git a/CraffftContaoDiscourseSSOBundle.php b/src/CraffftContaoDiscourseSSOBundle.php similarity index 100% rename from CraffftContaoDiscourseSSOBundle.php rename to src/CraffftContaoDiscourseSSOBundle.php diff --git a/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php similarity index 100% rename from DependencyInjection/Configuration.php rename to src/DependencyInjection/Configuration.php diff --git a/DependencyInjection/CraffftContaoDiscourseSSOExtension.php b/src/DependencyInjection/CraffftContaoDiscourseSSOExtension.php similarity index 100% rename from DependencyInjection/CraffftContaoDiscourseSSOExtension.php rename to src/DependencyInjection/CraffftContaoDiscourseSSOExtension.php diff --git a/FrontendModule/ModuleSSOProvider.php b/src/FrontendModule/ModuleSSOProvider.php similarity index 100% rename from FrontendModule/ModuleSSOProvider.php rename to src/FrontendModule/ModuleSSOProvider.php diff --git a/Resources/config/services.yml b/src/Resources/config/services.yml similarity index 100% rename from Resources/config/services.yml rename to src/Resources/config/services.yml diff --git a/Resources/contao/config/autoload.ini b/src/Resources/contao/config/autoload.ini similarity index 100% rename from Resources/contao/config/autoload.ini rename to src/Resources/contao/config/autoload.ini diff --git a/Resources/contao/config/config.php b/src/Resources/contao/config/config.php similarity index 100% rename from Resources/contao/config/config.php rename to src/Resources/contao/config/config.php diff --git a/Resources/contao/dca/tl_module.php b/src/Resources/contao/dca/tl_module.php similarity index 100% rename from Resources/contao/dca/tl_module.php rename to src/Resources/contao/dca/tl_module.php diff --git a/Resources/contao/dca/tl_settings.php b/src/Resources/contao/dca/tl_settings.php similarity index 100% rename from Resources/contao/dca/tl_settings.php rename to src/Resources/contao/dca/tl_settings.php diff --git a/Resources/contao/languages/de/modules.php b/src/Resources/contao/languages/de/modules.php similarity index 100% rename from Resources/contao/languages/de/modules.php rename to src/Resources/contao/languages/de/modules.php diff --git a/Resources/contao/languages/de/tl_settings.php b/src/Resources/contao/languages/de/tl_settings.php similarity index 100% rename from Resources/contao/languages/de/tl_settings.php rename to src/Resources/contao/languages/de/tl_settings.php diff --git a/Resources/contao/languages/en/modules.php b/src/Resources/contao/languages/en/modules.php similarity index 100% rename from Resources/contao/languages/en/modules.php rename to src/Resources/contao/languages/en/modules.php diff --git a/Resources/contao/languages/en/tl_settings.php b/src/Resources/contao/languages/en/tl_settings.php similarity index 100% rename from Resources/contao/languages/en/tl_settings.php rename to src/Resources/contao/languages/en/tl_settings.php diff --git a/SSO/SSOProviderPayload.php b/src/SSO/SSOProviderPayload.php similarity index 100% rename from SSO/SSOProviderPayload.php rename to src/SSO/SSOProviderPayload.php