ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ltiregstart.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 chdir("../../../");
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 } else {
39  ilObjLTIConsumer::sendResponseError(400, "missing required url parameter in request");
40 }
41 // optional
42 if ($params->has('typeid')) {
43  $typeId = $params->retrieve('typeid', $DIC->refinery()->kindlyTo()->listOf($DIC->refinery()->kindlyTo()->string()));
44 }
45 // create jwt token
48 if (!empty($typeId)) {
49  // In the context of an update, the aud is the id of the type.
50  $aud = strval($typeId);
52 }
53 try {
54  $now = time();
55  $token = [
56  "sub" => $DIC->user()->getId(),
57  "aud" => $clientId,
58  "scope" => $scope,
59  "iat" => $now,
60  "exp" => $now + 3600
61  ];
63  $regToken = Firebase\JWT\JWT::encode($token, $privateKey['key'], 'RS256', $privateKey['kid']);
64  if ($params->has('custom_params')) {
65  $customParams = urldecode($params->retrieve('custom_params', $DIC->refinery()->kindlyTo()->string()));
66  ilSession::set('lti_dynamic_registration_custom_params', $customParams);
67  }
68  ilSession::set('lti_dynamic_registration_client_id', $clientId);
69  header("Location: " . $url . "&openid_configuration=" . urlencode(ilObjLTIConsumer::getOpenidConfigUrl()) . "&registration_token=" . $regToken);
70 } catch (Exception $exception) {
71  ilObjLTIConsumer::sendResponseError(500, "error in ltiregstart.php: " . $exception->getMessage());
72 }
$scope
Definition: ltiregstart.php:47
static sendResponseError(int $code, string $message, $log=true)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
static initILIAS()
ilias initialisation
$token
Definition: ltiregstart.php:55
if($params->has('typeid')) $clientId
Definition: ltiregstart.php:46
$url
Definition: ltiregstart.php:33
$privateKey
Definition: ltiregstart.php:62
global $DIC
Definition: ltiregstart.php:25
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
static set(string $a_var, $a_val)
Set a value.
$regToken
Definition: ltiregstart.php:63
$typeId
Definition: ltiregstart.php:34