ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ltiregstart.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 chdir("../../");
23 
24 require_once("Services/Init/classes/class.ilInitialisation.php");
25 
27 global $DIC;
28 
30  ilObjLTIConsumer::sendResponseError(401, "unauthorized");
31 }
32 
33 $params = $DIC->http()->wrapper()->query();
34 
35 $url = '';
36 $typeId = '';
37 
38 if ($params->has('url')) {
39  $url = $params->retrieve('url', $DIC->refinery()->kindlyTo()->string());
40 
41  if (empty($_POST["url"]) || $_POST["url"] != $url) {
42  ilObjLTIConsumer::sendResponseError(400, "url parameter in request does not match url parameter in post");
43  }
44 } else {
45  ilObjLTIConsumer::sendResponseError(400, "missing required url parameter in request");
46 }
47 // optional
48 if ($params->has('typeid')) {
49  $typeId = $params->retrieve('typeid', $DIC->refinery()->kindlyTo()->listOf($DIC->refinery()->kindlyTo()->string()));
50 }
51 // create jwt token
54 if (!empty($typeId)) {
55  // In the context of an update, the aud is the id of the type.
56  $aud = strval($typeId);
58 }
59 try {
60  $now = time();
61  $token = [
62  "sub" => $DIC->user()->getId(),
63  "aud" => $clientId,
64  "scope" => $scope,
65  "iat" => $now,
66  "exp" => $now + 3600
67  ];
70  if ($params->has('custom_params')) {
71  $customParams = urldecode($params->retrieve('custom_params', $DIC->refinery()->kindlyTo()->string()));
72  ilSession::set('lti_dynamic_registration_custom_params', $customParams);
73  }
74  ilSession::set('lti_dynamic_registration_client_id', $clientId);
75  header("Location: " . $url . "&openid_configuration=" . urlencode(ilObjLTIConsumer::getOpenidConfigUrl()) . "&registration_token=" . $regToken);
76 } catch (Exception $exception) {
77  ilObjLTIConsumer::sendResponseError(500, "error in ltiregstart.php: " . $exception->getMessage());
78 }
$scope
Definition: ltiregstart.php:53
static sendResponseError(int $code, string $message, $log=true)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
static initILIAS()
ilias initialisation
$token
Definition: ltiregstart.php:61
if($params->has('typeid')) $clientId
Definition: ltiregstart.php:52
$url
Definition: ltiregstart.php:35
$privateKey
Definition: ltiregstart.php:68
global $DIC
Definition: ltiregstart.php:27
static encode(array $payload, $key, string $alg, string $keyId=null, array $head=null)
Converts and signs a PHP array into a JWT string.
Definition: JWT.php:199
static set(string $a_var, $a_val)
Set a value.
$regToken
Definition: ltiregstart.php:69
$typeId
Definition: ltiregstart.php:36