Commit 219e7553 authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon

Bug 1620879: Add fields to external_tokens to record client app

These fields can be used to indicate which client app
registered and/or is using the token

behatnotneeded: Can't be tested in Behat

Change-Id: I939c844cc5474fc799ddfd002a1052bb4ca67d1b
parent 872da913
......@@ -69,6 +69,9 @@
<FIELD NAME="publickey" TYPE="text" NOTNULL="true" DEFAULT="" SEQUENCE="false" COMMENT="created timestamp"/>
<FIELD NAME="publickeyexpires" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="created timestamp"/>
<FIELD NAME="wssigenc" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" SEQUENCE="false"/>
<FIELD NAME="clientname" TYPE="char" LENGTH="200" NOTNULL="false" SEQUENCE="false" COMMENT="Name of client program that generated and uses client."/>
<FIELD NAME="clientenv" TYPE="char" LENGTH="200" NOTNULL="false" SEQUENCE="false" COMMENT="Brief description of the environment of the client program (OS, browser, etc)"/>
<FIELD NAME="clientguid" TYPE="char" LENGTH="128" NOTNULL="false" SEQUENCE="false" COMMENT="Optional unique ID for the client program."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
......
......@@ -547,6 +547,21 @@ function xmldb_auth_webservice_upgrade($oldversion=0) {
) = '{$oldtail}'
"
);
log_debug('adding client info fields to external_tokens table');
$table = new XMLDBTable('external_tokens');
$field = new XMLDBField('clientname');
$field->setAttributes(XMLDB_TYPE_CHAR, 200);
add_field($table, $field);
$field = new XMLDBField('clientenv');
$field->setAttributes(XMLDB_TYPE_CHAR, 200);
add_field($table, $field);
$field = new XMLDBField('clientguid');
$field->setAttributes(XMLDB_TYPE_CHAR, 128);
add_field($table, $field);
}
// sweep for webservice updates everytime
......
......@@ -316,6 +316,9 @@ $string['restrictedusers'] = 'Authorised users only';
$string['fortokenusers'] = 'User token access';
$string['usertokens'] = 'Personal user tokens';
$string['serviceaccess'] = 'Service access';
$string['tokenclient'] = 'Client app';
$string['tokenclientunknown'] = '(Not specified)';
$string['tokenmanuallycreated'] = 'Manually created';
$string['gen'] = 'Generate';
$string['no_token'] = 'Token not generated';
$string['token_generated'] = 'Token generated';
......
......@@ -44,6 +44,8 @@ $dbservices = get_records_sql_array(
' . db_format_tsfield('et.ctime', 'token_ctime') . ',
et.institution,
et.validuntil as token_validuntil,
et.clientname,
et.clientenv,
esu.validuntil as user_validuntil,
esu.iprestriction
FROM
......@@ -87,6 +89,12 @@ if (!empty($dbservices)) {
'type' => 'html',
'value' => get_string('enabled'),
),
'client_info' => array(
'title' => ' ',
'datatable' => true,
'type' => 'html',
'value' => get_string('tokenclient', 'auth.webservice'),
),
'token' => array(
'title' => ' ',
'datatable' => true,
......@@ -133,6 +141,24 @@ if (!empty($dbservices)) {
'class' => 'text-center',
'key' => $service->dispid,
);
// Name of the client program that generated the token
if ($service->clientname) {
$client = "<b>{$service->clientname}</b>";
}
else {
$client = get_string('tokenclientunknown', 'auth.webservice');
}
if ($service->clientenv) {
$client .= " ({$service->clientenv})";
}
// information about the client that generated it
$userform['elements']['id' . $service->dispid . '_client_info'] = array(
'value' => $client,
'type' => 'html',
'key' => $service->dispid,
);
// token for the service if it exists
$userform['elements']['id' . $service->dispid . '_token'] = array(
'value' => (empty($service->token) ? get_string('no_token', 'auth.webservice') : $service->token),
......
......@@ -200,10 +200,13 @@ function get_ws_subsystems() {
* @param string $institution
* @param integer $validuntil
* @param string $iprestriction
* @param string $clientname (Optional) Human-readable name of client program using this token
* @param string $clientenv (Optional) Human-readable description of device/environment for client
* @param string $clientguid (Optional) Unique identifier for the client program
* @throws WebserviceException
* @return string token
*/
function webservice_generate_token($tokentype, $serviceorid, $userid, $institution = 'mahara', $validuntil=0, $iprestriction='') {
function webservice_generate_token($tokentype, $serviceorid, $userid, $institution = 'mahara', $validuntil = 0, $iprestriction = null, $clientname = null, $clientenv = null, $clientguid = null) {
global $USER;
// make sure the token doesn't exist (even if it should be almost impossible with the random generation)
$numtries = 0;
......@@ -237,9 +240,10 @@ function webservice_generate_token($tokentype, $serviceorid, $userid, $instituti
$newtoken->wssigenc = 0;
$newtoken->publickey = '';
$newtoken->validuntil = $validuntil;
if (!empty($iprestriction)) {
$newtoken->iprestriction = $iprestriction;
}
$newtoken->clientname = $clientname;
$newtoken->clientenv = $clientenv;
$newtoken->clientguid = $clientguid;
$newtoken->iprestriction = $iprestriction;
insert_record('external_tokens', $newtoken);
return $newtoken->token;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment