diff --git a/lib/externallib.php b/lib/externallib.php index f7394d01057..e6d5e99b955 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -773,7 +773,8 @@ function external_generate_token($tokentype, $serviceorid, $userid, $contextorid if (!empty($iprestriction)) { $newtoken->iprestriction = $iprestriction; } - $newtoken->privatetoken = null; + // Generate the private token, it must be transmitted only via https. + $newtoken->privatetoken = random_string(64); $DB->insert_record('external_tokens', $newtoken); return $newtoken->token; } diff --git a/webservice/lib.php b/webservice/lib.php index abb2ed16ad7..fe6c061c1c0 100644 --- a/webservice/lib.php +++ b/webservice/lib.php @@ -370,7 +370,8 @@ class webservice { $newtoken->contextid = context_system::instance()->id; $newtoken->creatorid = $userid; $newtoken->timecreated = time(); - $newtoken->privatetoken = null; + // Generate the private token, it must be transmitted only via https. + $newtoken->privatetoken = random_string(64); $DB->insert_record('external_tokens', $newtoken); }