ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ltiregstart.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22require_once("../vendor/composer/vendor/autoload.php");
23
25global $DIC;
26
28 ilObjLTIConsumer::sendResponseError(401, "unauthorized");
29}
30
31$params = $DIC->http()->wrapper()->query();
32
33$url = '';
35
36if ($params->has('url')) {
37 $url = $params->retrieve('url', $DIC->refinery()->kindlyTo()->string());
38
39 if (empty($_POST["url"]) || $_POST["url"] != $url) {
40 ilObjLTIConsumer::sendResponseError(400, "url parameter in request does not match url parameter in post");
41 }
42} else {
43 ilObjLTIConsumer::sendResponseError(400, "missing required url parameter in request");
44}
45// optional
46if ($params->has('typeid')) {
47 $typeId = $params->retrieve('typeid', $DIC->refinery()->kindlyTo()->listOf($DIC->refinery()->kindlyTo()->string()));
48}
49// create jwt token
52if (!empty($typeId)) {
53 // In the context of an update, the aud is the id of the type.
54 $aud = strval($typeId);
56}
57try {
58 $now = time();
60 "sub" => $DIC->user()->getId(),
61 "aud" => $clientId,
62 "scope" => $scope,
63 "iat" => $now,
64 "exp" => $now + 3600
65 ];
67 $regToken = Firebase\JWT\JWT::encode($token, $privateKey['key'], 'RS256', $privateKey['kid']);
68 if ($params->has('custom_params')) {
69 $customParams = urldecode($params->retrieve('custom_params', $DIC->refinery()->kindlyTo()->string()));
70 ilSession::set('lti_dynamic_registration_custom_params', $customParams);
71 }
72 ilSession::set('lti_dynamic_registration_client_id', $clientId);
73 header("Location: " . $url . "&openid_configuration=" . urlencode(ilObjLTIConsumer::getOpenidConfigUrl()) . "&registration_token=" . $regToken);
74} catch (Exception $exception) {
75 ilObjLTIConsumer::sendResponseError(500, "error in ltiregstart.php: " . $exception->getMessage());
76}
static initILIAS()
ilias initialisation
static sendResponseError(int $code, string $message, $log=true)
static set(string $a_var, $a_val)
Set a value.
$_POST['cmd']
Definition: lti.php:27
$token
Definition: ltiregstart.php:59
$privateKey
Definition: ltiregstart.php:66
$regToken
Definition: ltiregstart.php:67
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$scope
Definition: ltiregstart.php:51
global $DIC
Definition: ltiregstart.php:25
$typeId
Definition: ltiregstart.php:34
$url
Definition: ltiregstart.php:33
if($params->has('typeid')) $clientId
Definition: ltiregstart.php:50