Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace tool_mobile\local\hooks\user;
18
 
19
/**
20
 * Handles mobile app launches when third-party auth plugins are put in front of MFA.
21
 *
22
 * @package    tool_mobile
23
 * @copyright  2024 Juan Leyva
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
class after_user_passed_mfa {
27
 
28
    /**
29
     * Callback to recover $SESSION->wantsurl.
30
     *
31
     * @param \tool_mfa\hook\after_user_passed_mfa $hook
32
     */
33
    public static function callback(\tool_mfa\hook\after_user_passed_mfa $hook): void {
34
        global $SESSION, $CFG;
35
 
36
        // Check if the user is doing a mobile app launch, if that's the case, ensure $SESSION->wantsurl is correctly set.
37
        if (!NO_MOODLE_COOKIES && !empty($_COOKIE['tool_mobile_launch'])) {
38
            if (empty($SESSION->wantsurl) || strpos($SESSION->wantsurl, '/tool/mobile/launch.php') === false) {
39
 
40
                $params = json_decode($_COOKIE['tool_mobile_launch'], true);
41
                $SESSION->wantsurl = (new \moodle_url("/$CFG->admin/tool/mobile/launch.php", $params))->out(false);
42
                $SESSION->tool_mfa_has_been_redirected = true;  // Indicate MFA that they need to follow $SESSION->wantsurl.
43
            }
44
            // Invalidate cookie as we won't be needing it anymore.
45
            unset($_COOKIE['tool_mobile_launch']);
46
            if (!headers_sent()) {  // Just be very cautios as this is a critical code.
47
                setcookie('tool_mobile_launch', '', -1, $CFG->sessioncookiepath);
48
            }
49
        }
50
    }
51
}