-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxapitoken.php
More file actions
executable file
·159 lines (135 loc) · 4.51 KB
/
xapitoken.php
File metadata and controls
executable file
·159 lines (135 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Copyright (c) 2018 internetlehrer-gmbh.de
* GPLv2, see LICENSE
*/
/**
* xApi plugin: token generation script
*
* @author Uwe Kohnle <kohnle@internetlehrer-gmbh.de>
* @version $Id$
*/
$plugin = true;
// old required?
/*
if (empty($_COOKIE)) {
$_COOKIE = json_decode(base64_decode(rawurldecode($_GET['sess'])),TRUE);
}
*/
/**
* handle path context and includes
*/
if ($plugin) {
// Avoid redirection to start screen
// (see ilInitialisation::InitILIAS for details)
$_GET["baseClass"] = "ilStartUpGUI";
chdir("../../../../../../../");
require_once './Services/Init/classes/class.ilInitialisation.php';
require_once './Services/Object/classes/class.ilObjectFactory.php';
require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/XapiCmi5/classes/class.ilXapiCmi5AuthToken.php';
}
else
{
chdir("../../");
require_once 'libs/composer/vendor/autoload.php';
}
/**
* handle ILIAS Init old
*/
//require_once __DIR__.'/classes/XapiProxy/DataService.php';
//DataService::initIlias($client);
$tokenRestriction = true;
$origParam = $_GET['param'];
if (!isset($origParam) || !strlen($origParam))
{
$error = array('error-code' => 3,'error-text'=> 'invalid request: missing or empty param request parameter');
send($error);
}
try
{
$param = base64_decode(rawurldecode($origParam));
$param = json_decode(openssl_decrypt(
$param,
ilXapiCmi5AuthToken::OPENSSL_ENCRYPTION_METHOD,
ilXapiCmi5AuthToken::getWacSalt(),
0,
ilXapiCmi5AuthToken::OPENSSL_IV
), true);
$_COOKIE[session_name()] = $param[session_name()];
$_COOKIE['ilClientId'] = $param['ilClientId'];
$objId = $param['obj_id'];
$refId = $param['ref_id'];
#\XapiProxy\DataService::initIlias($_COOKIE['ilClientId']);
ilInitialisation::initILIAS();
$DIC = $GLOBALS['DIC'];
}
catch (Exception $e)
{
$error = array('error-code' => '3','error-text'=> 'internal server error');
send($error);
}
try
{
$object = ilObjectFactory::getInstanceByObjId($objId, false);
$token = ilXapiCmi5AuthToken::getInstanceByObjIdAndRefIdAndUsrId($objId, $refId, $DIC->user()->getId());
if ($object->getContentType() == $object::CONT_TYPE_CMI5)
{
$tokenCmi5Session = $token->getCmi5Session();
$alreadyReturnedCmi5Session = $token->getReturnedForCmi5Session();
if ($tokenCmi5Session == $alreadyReturnedCmi5Session)
{
// what about reloaded or refreshed pages?
// see: https://stackoverflow.com/questions/456841/detect-whether-the-browser-is-refreshed-or-not-using-php/456915
// Beware that the xapitoken request is an ajax request and not all clients send HTTP_REFERRER Header
if ($tokenRestriction == true)
{
$error = array('error-code' => '1','error-text'=> 'The authorization token has already been returned.');
send($error);
}
}
$token->setReturnedForCmi5Session($tokenCmi5Session);
$token->update();
}
if ($object->isBypassProxyEnabled()) {
$authToken = $object->getLrsType()->getBasicAuthWithoutBasic();
} else {
$authToken = base64_encode(CLIENT_ID . ':' . $token->getToken());
}
$response = array("auth-token" => $authToken);
send($response);
}
catch (Exception $e)
{
$error = array('error-code' => '2','error-text'=> 'could not create valid session from token.');
send($error);
}
function send($response)
{
header('Access-Control-Allow-Origin: '.$_SERVER["HTTP_ORIGIN"]);
header('Access-Control-Allow-Credentials: true');
header('Content-type:application/json;charset=utf-8');
echo json_encode($response);
exit;
}
/*
chdir("../../../../../../../");
if (empty($_COOKIE)) {
$_COOKIE = json_decode(base64_decode(rawurldecode($_GET['sess'])),TRUE);
}
// Avoid redirection to start screen
// (see ilInitialisation::InitILIAS for details)
$_GET["baseClass"] = "ilStartUpGUI";
require_once "./include/inc.header.php";
require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/XapiCmi5/classes/class.ilObjXapiCmi5.php";
$track_obj = new ilObjXapiCmi5();
$token = base64_encode(CLIENT_ID . ':' . $track_obj->getToken());
$res = array("auth-token" => $token);
function send($response)
{
header('Access-Control-Allow-Origin: '.$_SERVER["HTTP_ORIGIN"]);
header('Access-Control-Allow-Credentials: true');
header('Content-type:application/json;charset=utf-8');
echo json_encode($response);
exit;
}
*/