ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ltiregstart.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 require_once("../vendor/composer/vendor/autoload.php");
23 
25 global $DIC;
26 
28  ilObjLTIConsumer::sendResponseError(401, "unauthorized");
29 }
30 
31 $params = $DIC->http()->wrapper()->query();
32 
33 $url = '';
34 $typeId = '';
35 
36 if ($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
46 if ($params->has('typeid')) {
47  $typeId = $params->retrieve('typeid', $DIC->refinery()->kindlyTo()->listOf($DIC->refinery()->kindlyTo()->string()));
48 }
49 // create jwt token
52 if (!empty($typeId)) {
53  // In the context of an update, the aud is the id of the type.
54  $aud = strval($typeId);
56 }
57 try {
58  $now = time();
59  $token = [
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 }
$scope
Definition: ltiregstart.php:51
static sendResponseError(int $code, string $message, $log=true)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$_POST['cmd']
Definition: lti.php:27
static initILIAS()
ilias initialisation
$token
Definition: ltiregstart.php:59
if($params->has('typeid')) $clientId
Definition: ltiregstart.php:50
$url
Definition: ltiregstart.php:33
$privateKey
Definition: ltiregstart.php:66
global $DIC
Definition: ltiregstart.php:25
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:13
static set(string $a_var, $a_val)
Set a value.
$regToken
Definition: ltiregstart.php:67
$typeId
Definition: ltiregstart.php:34