Skip to content

Commit

Permalink
MDL-59510 core_oauth2: add oauth2_refresh_token table
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Oct 5, 2020
1 parent 87afa4d commit 6502c13
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4300,5 +4300,24 @@
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" COMMENT="Foreign key for the userid"/>
</KEYS>
</TABLE>
<TABLE NAME="oauth2_refresh_token" COMMENT="Stores refresh tokens which can be exchanged for access tokens">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Time this record was created."/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Time this record was modified."/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The user to whom this refresh token belongs."/>
<FIELD NAME="issuerid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Corresponding oauth2 issuer"/>
<FIELD NAME="token" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="refresh token"/>
<FIELD NAME="scopehash" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" COMMENT="sha1 hash of the scopes used when requesting the refresh token"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="issueridkey" TYPE="foreign" FIELDS="issuerid" REFTABLE="oauth2_issuer" REFFIELDS="id" COMMENT="Issuer id foreign key"/>
<KEY NAME="useridkey" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" COMMENT="User id foreign key"/>
</KEYS>
<INDEXES>
<INDEX NAME="userid-issuerid-scopehash" UNIQUE="true" FIELDS="userid, issuerid, scopehash"/>
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
30 changes: 30 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2708,5 +2708,35 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021052500.15);
}

if ($oldversion < 2021052500.19) {
// Define table oauth2_refresh_token to be created.
$table = new xmldb_table('oauth2_refresh_token');

// Adding fields to table oauth2_refresh_token.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('issuerid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('token', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('scopehash', XMLDB_TYPE_CHAR, 40, null, XMLDB_NOTNULL, null, null);

// Adding keys to table oauth2_refresh_token.
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
$table->add_key('issueridkey', XMLDB_KEY_FOREIGN, ['issuerid'], 'oauth2_issuer', ['id']);
$table->add_key('useridkey', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);

// Adding indexes to table oauth2_refresh_token.
$table->add_index('userid-issuerid-scopehash', XMLDB_INDEX_UNIQUE, array('userid', 'issuerid', 'scopehash'));

// Conditionally launch create table for oauth2_refresh_token.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2021052500.19);
}

return true;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2021052500.18; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021052500.19; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20201002)'; // Human-friendly version name
Expand Down

0 comments on commit 6502c13

Please sign in to comment.