This repository was archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
74 lines (62 loc) · 2.1 KB
/
index.php
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
<?php
require_once 'common.inc.php';
use smtech\CanvasHack\Toolbox;
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider;
use smtech\ReflexiveCanvasLTI\Exception\ConfigurationException;
define('ACTION_CONFIG', 'config');
define('ACTION_INSTALL', 'install');
define('ACTION_CONSUMERS', 'consumers');
define('ACTION_UNSPECIFIED', false);
/* store any requested actions for future handling */
$action = (empty($_REQUEST['action']) ?
ACTION_UNSPECIFIED :
strtolower($_REQUEST['action'])
);
/* action requests only come from outside the LTI! */
if ($action) {
unset($_SESSION[ToolProvider::class]);
}
/* authenticate LTI launch request, if present */
if ($toolbox->lti_isLaunching()) {
$toolbox->resetSession();
$toolbox->lti_authenticate();
exit;
}
/* if authenticated LTI launch, head off to app.php */
if (!empty($_SESSION[ToolProvider::class]['canvas'])) {
header("Location: control-panel.php");
exit;
/* if not authenticated, default to showing credentials */
} else {
$action = (empty($action) ?
ACTION_CONFIG :
$action
);
}
/* process any actions */
switch ($action) {
/* reset cached install data from config file */
case ACTION_INSTALL:
$_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true);
$toolbox =& $_SESSION['toolbox'];
/* test to see if we can connect to the API */
try {
$toolbox->getAPI();
} catch (ConfigurationException $e) {
/* if there isn't an API token in config.xml, are there OAuth credentials? */
if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) {
$toolbox->interactiveGetAccessToken();
exit;
} else { /* no (understandable) API credentials available -- doh! */
throw $e;
}
}
/* finish by opening consumers control panel */
header('Location: consumers.php');
exit;
/* show LTI configuration XML file */
case ACTION_CONFIG:
header('Content-type: application/xml');
echo $toolbox->saveConfigurationXML();
exit;
}