PHP code example of centertap / discourse-sso-consumer
1. Go to this page and download the library: Download centertap/discourse-sso-consumer library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
centertap / discourse-sso-consumer example snippets
...
wfLoadExtension( 'PluggableAuth' );
wfLoadExtension( 'DiscourseSsoConsumer' );
...
$wgPluggableAuth_Config = [
'MY-BUTTON-LABEL' => [ 'plugin' => 'DiscourseSsoConsumer' ]
];
># Allow auth extensions to generate new local users.
>$wgGroupPermissions['*']['autocreateaccount'] = true;
>
$wgHooks['DiscourseSsoConsumer_Configure'][] =
function ( array &$config ) {
$config['DiscourseUrl'] = 'https://discourse.example.org';
$config['Sso']['Enable'] = true;
$config['Sso']['SharedSecret'] = 'SETECAstronomy';
$config['Sso']['EnableSeamlessLogin'] = true;
$config['Sso']['EnableAutoRelogin'] = true;
$config['GroupMaps'] = [
'sysop' => [ '@ADMIN@' ],
'bureaucrat' => [ '@ADMIN@' ],
'quitetrusted' => [ 'trust_level_3',
'trust_level_4',
],
];
$config['Webhook']['Enable'] = true;
$config['Webhook']['SharedSecret'] = 'MyVoiceIsMyPassword';
$config['Webhook']['AllowedIpList'][] = '192.168.22.11';
return true;
};
[ 'MW-GROUP-1' => [ 'D-GROUP-X', 'D-GROUP-Y', ... ],
'MW-GROUP-2' => [ 'D-GROUP-A', 'D-GROUP-B', ... ], ]
[ 'sysop' => [ '@ADMIN@' ],
'bureaucrat' => [ '@ADMIN@' ] ];
use MediaWiki\Extension\DiscourseSsoConsumer\ApiV1\Connector;
function getUserAvatarUrlAndTimezone( User $user, int $size ) {
$record = Connector::getUserRecord( $user );
$template = $record->user_record->avatar_template ?? null;
$avatarUrl = null;
if ( $template !== null ) {
$avatarUrl = str_replace( '{size}', (string)$size, $template );
}
$timezone = $record->user_record->user_option->timezone ?? null;
return [ $avatarUrl, $timezone ];
}