Issues (59)

callback.php (1 issue)

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
/**
18
 * Handles Edulegit webhooks
19
 *
20
 * @package   assignsubmission_edulegit
21
 * @author    Alex Crosby <[email protected]>
22
 * @copyright @2024 EduLegit.com
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
define('NO_MOODLE_COOKIES', true);
26
27
require_once(dirname(__DIR__) . '/../../../config.php');
28
29
try {
30
    $rawbody = file_get_contents('php://input');
31
    if (!$rawbody) {
32
        header('HTTP/1.1 400 Bad Request');
33
        die;
34
    }
35
36
    $token = get_config('assignsubmission_edulegit', 'api_token');
0 ignored issues
show
The function get_config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
    $token = /** @scrutinizer ignore-call */ get_config('assignsubmission_edulegit', 'api_token');
Loading history...
37
    $validator = new \assignsubmission_edulegit\edulegit_payload_validator($token);
38
39
    $payload = \assignsubmission_edulegit\edulegit_helper::json_decode($rawbody);
40
41
    if (!$validator->is_valid($payload)) {
42
        header('HTTP/1.1 400 Bad Request');
43
        die;
44
    }
45
46
    if (!$validator->is_signed($payload)) {
47
        header('HTTP/1.1 403 Invalid signature');
48
        die;
49
    }
50
51
    $callback = new \assignsubmission_edulegit\edulegit_callback();
52
    $result = $callback->handle($payload);
53
54
    echo \assignsubmission_edulegit\edulegit_helper::json_encode($result);
55
} catch (\Throwable $exception) {
56
    header('HTTP/1.1 400 Bad Request');
57
    throw $exception;
58
}
59