MDL-58219 oauth2: Show connected system account info

Show the username and email of the connected system account (if it ever requires refreshing - this will help identity the account
to re-authorise).

Part of MDL-58220
This commit is contained in:
Damyon Wiese
2017-04-03 13:41:18 +08:00
parent 1a1a09d8f8
commit 28dddbc129
9 changed files with 37 additions and 7 deletions
@@ -114,7 +114,9 @@ class renderer extends plugin_renderer_base {
// Connected.
if ($issuer->is_system_account_connected()) {
$systemauth = $OUTPUT->pix_icon('yes', get_string('systemaccountconnected', 'tool_oauth2'), 'tool_oauth2');
$systemaccount = \core\oauth2\api::get_system_account($issuer);
$systemauth = s($systemaccount->get('email')) . ' (' . s($systemaccount->get('username')). ') ';
$systemauth .= $OUTPUT->pix_icon('yes', get_string('systemaccountconnected', 'tool_oauth2'), 'tool_oauth2');
} else {
$systemauth = $OUTPUT->pix_icon('no', get_string('systemaccountnotconnected', 'tool_oauth2'), 'tool_oauth2');
}
Regular → Executable
+3 -3
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="auth/oauth2/db" VERSION="20170308" COMMENT="XMLDB file for Moodle auth/oauth2"
<XMLDB PATH="auth/oauth2/db" VERSION="20170310" COMMENT="XMLDB file for Moodle auth/oauth2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@@ -13,7 +13,7 @@
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The user account this oauth login is linked to."/>
<FIELD NAME="issuerid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="username" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The external username to map to this moodle account"/>
<FIELD NAME="email" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The external email to map to this moodle account"/>
<FIELD NAME="email" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The external email to map to this moodle account"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@@ -27,4 +27,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
+13
View File
@@ -70,5 +70,18 @@ function xmldb_auth_oauth2_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2017030700, 'auth', 'oauth2');
}
if ($oldversion < 2017031000) {
// Changing type of field email on table auth_oauth2_linked_login to text.
$table = new xmldb_table('auth_oauth2_linked_login');
$field = new xmldb_field('email', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'username');
// Launch change of type for field email.
$dbman->change_field_type($table, $field);
// Oauth2 savepoint reached.
upgrade_plugin_savepoint(true, 2017031000, 'auth', 'oauth2');
}
return true;
}
+1 -1
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017030700; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2017031000; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2016112900; // Requires this Moodle version
$plugin->component = 'auth_oauth2'; // Full name of the plugin (used for diagnostics)
+5
View File
@@ -715,10 +715,15 @@ class api {
if ($systemaccount) {
$systemaccount->delete();
}
$userinfo = $client->get_userinfo();
$record = new stdClass();
$record->issuerid = $issuer->get('id');
$record->refreshtoken = $refreshtoken;
$record->grantedscopes = $scopes;
$record->email = $userinfo['email'];
$record->username = $userinfo['username'];
$systemaccount = new system_account(0, $record);
+6
View File
@@ -55,6 +55,12 @@ class system_account extends persistent {
),
'grantedscopes' => array(
'type' => PARAM_RAW,
),
'email' => array(
'type' => PARAM_RAW,
),
'username' => array(
'type' => PARAM_RAW,
)
);
}
+3 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20170228" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20170310" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -3510,6 +3510,8 @@
<FIELD NAME="issuerid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The id of the oauth 2 identity issuer"/>
<FIELD NAME="refreshtoken" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The refresh token used to request access tokens."/>
<FIELD NAME="grantedscopes" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The scopes that this system account has been granted access to."/>
<FIELD NAME="email" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The email that was connected to this issuer."/>
<FIELD NAME="username" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The username that was connected as a system account to this issue."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+2
View File
@@ -2686,6 +2686,8 @@ function xmldb_main_upgrade($oldversion) {
$table->add_field('issuerid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('refreshtoken', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('grantedscopes', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('username', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('email', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
// Adding keys to table oauth2_system_account.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2017033100.02; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017033100.03; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.