Skip to content

Sign-On-O-Tron support #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions VENDOR CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ List here the hacks that need to be done in the 'vendor' folder.

* pixelfear/oauth2-dropbox
=> nothing to do, just saying that I actually use a personal fork of this rep where I changed the require version of League oauth2.

* learningpool/oauth2-signonotron
=> open src/Provider/signonotron.ini.dist, add your site's URL, and save the file as signonotron.ini
10 changes: 7 additions & 3 deletions auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ public function loginpage_hook() {
break;
case 'github':
case 'dropbox':
// As Github/Dropbox doesn't provide firstname/lastname, we'll split the name at the first whitespace.
case 'signonotron':
// As Github/Dropbox/Signonotron doesn't provide firstname/lastname, we'll split the name at the first whitespace.
$githubusername = explode(' ', $userdetails->name, 2);
$newuser->firstname = $githubusername[0];
$newuser->lastname = $githubusername[1];
Expand Down Expand Up @@ -406,7 +407,7 @@ public function loginpage_hook() {
$content = str_replace(array("\n", "\r"), array("\\\n", "\\\r"), auth_googleoauth2_display_buttons(false));
$PAGE->requires->css('/auth/googleoauth2/style.css');
$PAGE->requires->js_init_code("buttonsCodeOauth2 = '$content';");
$PAGE->requires->js(new moodle_url($CFG->wwwroot . "/auth/googleoauth2/script.js"));
$PAGE->requires->js(new moodle_url($CFG->httpswwwroot . "/auth/googleoauth2/script.js"));
}
}
}
Expand Down Expand Up @@ -645,6 +646,7 @@ function drawChart() {
[\'Dropbox\', ' . $providerstats->dropbox . ' ],
[\'VK\', ' . $providerstats->vk . ' ],
[\'Battle.net\', ' . $providerstats->battlenet . ' ],
[\'Sign-On-O-Tron\', ' . $providerstats->signonotron . ' ],
[\''.$strothermoodle.'\', ' . $providerstats->moodle . ' ]
]);

Expand All @@ -660,7 +662,8 @@ function drawChart() {
5: { color: \'#007ee5\'},
6: { color: \'#45668e\'},
7: { color: \'#00B4FF\'},
8: { color: \'#ee7600\'}
8: { color: \'#ee7600\'},
9: { color: \'#c900ad\'}
}
};

Expand Down Expand Up @@ -695,6 +698,7 @@ public function get_stats($periodindays = 60) {
'vk' => 0,
'battlenet' => 0,
'moodle' => 0,
'signonotron' => 0,
'periodindays' => $periodindays);

// Retrieve the provider stats.
Expand Down
68 changes: 68 additions & 0 deletions classes/provider/signonotron.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
// This file is part of Oauth2 authentication plugin for Moodle.
//
// Oauth2 authentication plugin for Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Oauth2 authentication plugin for Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Oauth2 authentication plugin for Moodle. If not, see <http://www.gnu.org/licenses/>.

require_once($CFG->dirroot . '/auth/googleoauth2/vendor/autoload.php');

class provideroauth2signonotron extends Learningpool\OAuth2\Client\Provider\Signonotron {

// THE VALUES YOU WANT TO CHANGE WHEN CREATING A NEW PROVIDER.
public $sskstyle = 'signonotron';
public $name = 'signonotron'; // It must be the same as the XXXXX in the class name provideroauth2XXXXX.
public $readablename = 'Sign-On-O-Tron';
public $scopes = array();

/**
* Constructor.
*
* @throws Exception
* @throws dml_exception
*/
public function __construct() {
global $CFG;

parent::__construct([
'clientId' => get_config('auth/googleoauth2', $this->name . 'clientid'),
'clientSecret' => get_config('auth/googleoauth2', $this->name . 'clientsecret'),
'redirectUri' => preg_replace('/http:/',
'https:', $CFG->httpswwwroot .'/auth/googleoauth2/' . $this->name . '_redirect.php', 1),
'scopes' => $this->scopes
]);
}

/**
* Is the provider enabled.
*
* @return bool
* @throws Exception
* @throws dml_exception
*/
public function isenabled() {
return (get_config('auth/googleoauth2', $this->name . 'clientid')
&& get_config('auth/googleoauth2', $this->name . 'clientsecret'));
}

/**
* The html button.
*
* @param $authurl
* @param $providerdisplaystyle
* @return string
* @throws coding_exception
*/
public function html_button($authurl, $providerdisplaystyle) {
return googleoauth2_html_button($authurl, $providerdisplaystyle, $this);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"require": {
"league/oauth2-client": "^0.12.1",
"depotwarehouse/oauth2-bnet": "^3.0",
"pixelfear/oauth2-dropbox": "dev-bugfix"
"pixelfear/oauth2-dropbox": "dev-bugfix",
"learningpool/oauth2-signonotron": "dev-master"
}
}
7 changes: 7 additions & 0 deletions lang/en/auth_googleoauth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
$string['auth_microsoftclientid_key'] = 'Microsoft v2 Application ID';
$string['auth_microsoftclientsecret'] = '';
$string['auth_microsoftclientsecret_key'] = 'Microsoft v2 Application secret';
$string['auth_signonotronclientid'] = 'Information on how to generate the Sign-On-O-Tron Client ID/Secret can be found <a href = "https://github.com/alphagov/signonotron2/blob/master/doc/usage.md" target="_blank">here</a>. Sign-On-O-Tron only accepts HTTPS. Sign-On-O-Tron requires some additional setup, see VENDOR CHANGES.md and the readme at: googleoauth2/vendor/learningpool/oauth2-signonotron/README.md
<br/>Site URL: {$a->siteurl}
<br/>Site domain: {$a->sitedomain}
<br/>Valid OAuth redirect URIs: {$a->callbackurl}';
$string['auth_signonotronclientid_key'] = 'Sign-On-O-Tron Client ID';
$string['auth_signonotronclientsecret'] = 'See above.';
$string['auth_signonotronclientsecret_key'] = 'Sign-On-O-Tron Client secret';
$string['microsoft_failure'] = 'Did not receive an authorization code from the Microsoft servers.';
$string['auth_googlesettings'] = 'Settings';
$string['couldnotauthenticate'] = 'The authentication failed - Please try to sign-in again.';
Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function googleoauth2_html_button($authurl, $providerdisplaystyle, $provider) {
* @return array
*/
function provider_list() {
return array('google', 'facebook', 'battlenet', 'github', 'linkedin', 'messenger', 'microsoft', 'vk', 'dropbox');
return array('google', 'facebook', 'battlenet', 'github', 'linkedin', 'messenger', 'microsoft', 'vk', 'dropbox', 'signonotron');
}

/**
Expand Down
19 changes: 19 additions & 0 deletions signonotron_redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
// This file is part of Oauth2 authentication plugin for Moodle.
//
// Oauth2 authentication plugin for Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Oauth2 authentication plugin for Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Oauth2 authentication plugin for Moodle. If not, see <http://www.gnu.org/licenses/>.

require('../../config.php');
require_once($CFG->dirroot . '/auth/googleoauth2/lib.php');
googleoauth2_provider_redirect('signonotron');