Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
122 lines (105 loc) · 4.6 KB
/
Copy pathindex.php
File metadata and controls
122 lines (105 loc) · 4.6 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
<?php
// https://github.com/tsugicontrib/sakaiapi
require_once "../config.php";
use \Tsugi\Core\LTIX;
use \Tsugi\Util\U;
use \Tsugi\UI\Output;
require_once "util.php";
$LTI = LTIX::requireData();
require_once("nav.php");
$probe_preset = U::get($_GET, 'probe');
if ( $probe_preset === '1' ) {
$probe_preset = 'lti';
}
$probe_target = 'api';
$scope_preset = $probe_preset;
if ( is_string($probe_preset) && strpos($probe_preset, '-direct') !== false ) {
$probe_target = 'direct';
$scope_preset = str_replace('-direct', '', $probe_preset);
}
$do_probe = ($scope_preset === 'lti' || $scope_preset === 'sakai');
$probe_result = false;
if ( $do_probe ) {
$probe_result = sakai_get_token_and_probe($LTI, $scope_preset, $probe_target);
}
$OUTPUT->header();
$OUTPUT->bodyStart();
$OUTPUT->topNav($menu);
$OUTPUT->welcomeUserCourse();
$issuer = htmlentities($LTI->ltiParameter('issuer_key'));
$token_url = htmlentities($LTI->ltiParameter('lti13_token_url'));
$api_root = sakai_api_root($LTI);
$direct_root = sakai_direct_root($LTI);
$probe_url = sakai_bearer_probe_url($LTI);
$direct_probe_url = sakai_direct_bearer_probe_url($LTI);
?>
<h1>Sakai API bearer test</h1>
<p>
This tool obtains a Sakai Access Token (SAT) via the LTI Advantage client-credentials
flow, then calls a bearer probe with <code>Authorization: Bearer</code> on
<code>/api</code> or <code>/direct</code>.
</p>
<dl class="dl-horizontal">
<dt>Issuer</dt><dd><?= $issuer ?></dd>
<dt>Token URL</dt><dd><code><?= $token_url ?></code></dd>
<dt>API root</dt><dd><code><?= htmlentities($api_root ? $api_root : '(unknown)') ?></code></dd>
<dt>/api probe</dt><dd><code><?= htmlentities($probe_url ? $probe_url : '(unknown)') ?></code></dd>
<dt>/direct root</dt><dd><code><?= htmlentities($direct_root ? $direct_root : '(unknown)') ?></code></dd>
<dt>/direct probe</dt><dd><code><?= htmlentities($direct_probe_url ? $direct_probe_url : '(unknown)') ?></code></dd>
</dl>
<h2>Probe tests</h2>
<p class="text-muted">
Token audience follows normal LTI rules from your issuer registration.
Optional overrides: <code>sakai_token_scope</code>, <code>sakai_api_root</code>,
<code>sakai_direct_root</code>.
</p>
<p>
<a class="btn btn-primary" href="index.php?probe=lti">LTI scope & /api probe</a>
<a class="btn btn-default" href="index.php?probe=sakai">Sakai scope & /api probe</a>
<a class="btn btn-primary" href="index.php?probe=lti-direct">LTI scope & /direct probe</a>
<a class="btn btn-default" href="index.php?probe=sakai-direct">Sakai scope & /direct probe</a>
</p>
<ul class="text-muted">
<li><strong>LTI scope:</strong> <code>https://purl.imsglobal.org/spec/lti-ags/scope/lineitem</code> (working)</li>
<li><strong>Sakai scope:</strong> <code>sakai.lti.api.content.read</code> (expected to fail until granted in Sakai)</li>
</ul>
<?php if ( $do_probe ) { ?>
<div id="probe-results">
<h2>Results — <?= htmlentities($probe_result ? $probe_result['preset_label'] : '') ?>
on <?= htmlentities($probe_result ? $probe_result['probe_target_label'] : '') ?></h2>
<?php if ( $probe_result && is_array($probe_result['scopes']) ) { ?>
<p><strong>Scopes requested:</strong></p>
<pre><?= htmlentities(implode("\n", $probe_result['scopes'])) ?></pre>
<?php } ?>
<?php if ( $probe_result && $probe_result['ok'] ) { ?>
<div class="alert alert-success">Probe succeeded (HTTP <?= (int) $probe_result['probe_http_code'] ?>).</div>
<?php } else { ?>
<div class="alert alert-warning">Probe did not report success.
<?php if ( $probe_result && $probe_result['probe_http_code'] ) { ?>
HTTP <?= (int) $probe_result['probe_http_code'] ?>.
<?php } ?>
<?php if ( $probe_result && ! $probe_result['access_token'] ) { ?>
Token request failed or returned no <code>access_token</code> (expected for Sakai-only scope until configured).
<?php } ?>
<?php if ( $probe_result && U::strlen($probe_result['missing']) > 0 ) { ?>
Missing: <?= htmlentities($probe_result['missing']) ?>.
<?php } ?>
</div>
<?php } ?>
<?php if ( $probe_result && is_array($probe_result['token_data']) ) { ?>
<h3>Token response</h3>
<pre><?= htmlentities(Output::safe_print_r($probe_result['token_data'])) ?></pre>
<?php } ?>
<?php if ( $probe_result && $probe_result['access_token'] ) { ?>
<h3>Access token (SAT)</h3>
<pre><?= htmlentities($probe_result['access_token']) ?></pre>
<?php } ?>
<?php if ( $probe_result && $probe_result['probe_body'] !== false ) { ?>
<h3>Probe response</h3>
<pre><?= htmlentities($probe_result['probe_body']) ?></pre>
<?php } ?>
<?php sakai_print_debug_log('debug_log', $probe_result ? $probe_result['debug_log'] : array()); ?>
</div>
<?php } ?>
<?php
$OUTPUT->footer();