ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
xapitoken.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once __DIR__ . '/../vendor/composer/vendor/autoload.php';
33
34$origParam = $_GET['param'];
35
36if (!isset($origParam) || !strlen($origParam)) {
37 $error = array('error-code' => 3,'error-text' => 'invalid request: missing or empty param request parameter');
38 send($error);
39}
40
41try {
42 $param = base64_decode(rawurldecode($origParam));
43
44 $param = json_decode(openssl_decrypt(
45 $param,
48 0,
50 ), true);
51
52 // @phpstan-ignore ilias.superglobalWrite.v12 (restores session and client id from the signed token before ilInitialisation runs, so no HTTP service exists yet)
53 $_COOKIE[session_name()] = $param[session_name()];
54
55 // @phpstan-ignore ilias.superglobalWrite.v12 (restores session and client id from the signed token before ilInitialisation runs, so no HTTP service exists yet)
56 $_COOKIE['ilClientId'] = $param['ilClientId'];
57 $objId = $param['obj_id'];
58 $refId = $param['ref_id'];
59
61 $DIC = $GLOBALS['DIC'];
62} catch (ilCmiXapiException $e) {
63 $error = array('error-code' => '3','error-text' => 'internal server error');
64 send($error);
65}
66
67try {
70 if ($object->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5) {
71 $tokenCmi5Session = $token->getCmi5Session();
72 $alreadyReturnedCmi5Session = $token->getReturnedForCmi5Session();
73 if ($tokenCmi5Session == $alreadyReturnedCmi5Session) {
74 // what about reloaded or refreshed pages?
75 // see: https://stackoverflow.com/questions/456841/detect-whether-the-browser-is-refreshed-or-not-using-php/456915
76 // Beware that the xapitoken request is an ajax request and not all clients send HTTP_REFERRER Header
77 if ($tokenRestriction == true) {
78 $error = array('error-code' => '1','error-text' => 'The authorization token has already been returned.');
79 send($error);
80 }
81 }
82 $token->setReturnedForCmi5Session($tokenCmi5Session);
83 $token->update();
84 }
85 if ($object->isBypassProxyEnabled()) {
86 $authToken = $object->getLrsType()->getBasicAuthWithoutBasic();
87 } else {
88 $authToken = base64_encode(CLIENT_ID . ':' . $token->getToken());
89 }
90
91
92 $response = array("auth-token" => $authToken);
94} catch (ilCmiXapiException $e) {
95 $error = array('error-code' => '2','error-text' => 'could not create valid session from token.');
96 send($error);
97}
98
99function send($response): void
100{
101 if (isset($_SERVER["HTTP_ORIGIN"]) && $_SERVER["HTTP_ORIGIN"] != "") {
102 header('Access-Control-Allow-Origin: ' . $_SERVER["HTTP_ORIGIN"]);
103 }
104 header('Access-Control-Allow-Credentials: true');
105 header('Content-type:application/json;charset=utf-8');
106 echo json_encode($response);
107 exit;
108}
static getInstanceByObjIdAndRefIdAndUsrId(int $objId, int $refId, int $usrId, bool $checkValid=true)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
const CLIENT_ID
Definition: constants.php:41
$_GET['cmd']
Endpoint a platform launches ILIAS objects at, with any LTI version: the launch logs the user in thro...
Definition: lti.php:29
$GLOBALS["DIC"]
Definition: wac.php:66
$token
Definition: xapitoken.php:69
$DIC
Definition: xapitoken.php:61
$_COOKIE[session_name()]
Definition: xapitoken.php:53
$objId
Definition: xapitoken.php:57
$tokenRestriction
see: https://github.com/AICC/CMI-5_Spec_Current/blob/quartz/cmi5_spec.md#fetch_url response should al...
Definition: xapitoken.php:32
catch(ilCmiXapiException $e) send($response)
Definition: xapitoken.php:99
$origParam
Definition: xapitoken.php:34
$refId
Definition: xapitoken.php:58
$param
Definition: xapitoken.php:44
$response
Definition: xapitoken.php:92
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...