mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-65518 badges: Retry auth test
When testing the site backpack login credentials, don't rely on a previous login because the username and password could have changed.
This commit is contained in:
parent
c659b1c53d
commit
2fe34536d5
@ -473,6 +473,21 @@ class backpack_api {
|
||||
return $this->curl_request('issuers', null, null, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete any user access tokens in the session so we will attempt to get new ones.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear_system_user_session() {
|
||||
global $SESSION;
|
||||
|
||||
$useridkey = $this->get_token_key(BADGE_USER_ID_TOKEN);
|
||||
unset($SESSION->$useridkey);
|
||||
|
||||
$expireskey = $this->get_token_key(BADGE_EXPIRES_TOKEN);
|
||||
unset($SESSION->$expireskey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate using the stored email and password and save the valid access tokens.
|
||||
*
|
||||
|
@ -1173,7 +1173,8 @@ function badge_assemble_notification(stdClass $badge) {
|
||||
|
||||
/**
|
||||
* Attempt to authenticate with the site backpack credentials and return an error
|
||||
* if the authentication fails.
|
||||
* if the authentication fails. If external backpacks are not enabled, this will
|
||||
* not perform any test.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -1189,6 +1190,10 @@ function badges_verify_site_backpack() {
|
||||
if (empty($backpack->apiversion) || ($backpack->apiversion == OPEN_BADGES_V2)) {
|
||||
$backpackapi = new \core_badges\backpack_api($backpack);
|
||||
|
||||
// Clear any cached access tokens in the session.
|
||||
$backpackapi->clear_system_user_session();
|
||||
|
||||
// Now attempt a login with these credentials.
|
||||
$result = $backpackapi->authenticate();
|
||||
if ($result === false || !empty($result->error)) {
|
||||
$warning = $backpackapi->get_authentication_error();
|
||||
|
Loading…
x
Reference in New Issue
Block a user