19declare(strict_types=1);
39 private \ILIAS\DI\Container
$dic;
49 $this->
lng = $DIC->language();
50 $this->
user = $DIC->user();
64 $command =
$DIC->ctrl()->getCmd(self::CMD_LAUNCH);
74 if ($this->
object->getProvider()->getLtiVersion() ==
"LTI-1p0") {
75 if ($this->
object->isLaunchMethodEmbedded()) {
76 $tpl =
new ilTemplate(
'tpl.lti_content.html',
true,
true,
'components/ILIAS/LTIConsumer');
77 $tpl->setVariable(
"EMBEDDED_IFRAME_SRC", $this->dic->ctrl()->getLinkTarget(
79 self::CMD_SHOW_EMBEDDED
81 $this->dic->ui()->mainTemplate()->setContent($tpl->get());
88 $tpl =
new ilTemplate(
'tpl.lti_content.html',
true,
true,
'components/ILIAS/LTIConsumer');
89 $tpl->setVariable(
"EMBEDDED_IFRAME_SRC", $this->dic->ctrl()->getLinkTarget(
91 self::CMD_SHOW_EMBEDDED
93 $this->dic->ui()->mainTemplate()->setContent($tpl->get());
99 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
'failure',
'initialLogin Error: ',
true);
101 $response = $this->dic->http()->response()->withBody(
ILIAS\Filesystem\Stream\Streams::ofString($form));
102 $this->dic->http()->saveResponse(
$response);
103 $this->dic->http()->sendResponse();
104 $this->dic->http()->close();
106 } elseif (!$this->
object->isLaunchMethodEmbedded()) {
123 if (isset($loginData[
'state'])) {
124 $params[
'state'] = $loginData[
'state'];
127 $r =
'<form action="' . $loginData[
'redirect_uri'] .
"\" name=\"ltiAuthForm\" id=\"ltiAuthForm\" " .
128 "method=\"post\" enctype=\"application/x-www-form-urlencoded\">\n";
130 foreach (
$params as $key => $value) {
131 $key = htmlspecialchars($key);
132 $value = htmlspecialchars($value);
133 $r .=
" <input type=\"hidden\" name=\"{$key}\" value=\"{$value}\"/>\n";
137 $r .=
"<script type=\"text/javascript\">\n" .
139 "document.ltiAuthForm.submit();\n" .
149 if ($this->
object->getOfflineStatus() ||
150 $this->object->isLaunchMethodEmbedded() ||
157 $this->user->getId(),
158 $this->object->getProvider()->getPrivacyIdent()
161 if ($user_ident ==
'' || $user_ident ==
null) {
167 $context = $ilLTIConsumerLaunch->getContext();
168 $contextType = $ilLTIConsumerLaunch::getLTIContextType(
$context[
"type"]);
169 $contextId = (string)
$context[
"id"];
173 $this->dic->user()->getId(),
174 $this->object->getRefId(),
175 $this->object->getId()
178 $returnUrl = !$this->
object->isLaunchMethodOwnWin() ?
'' : str_replace(
184 $launchParameters = $this->
object->buildLaunchParameters(
193 $target = $this->
object->getLaunchMethod() ==
"newWin" ?
"_blank" :
"_self";
194 $button =
'<input class="btn btn-default ilPre" type="button" onClick="ltilaunch()" value = "' . $this->
lng->txt(
"show_content") .
'" />';
195 $output =
'<form id="lti_launch_form" name="lti_launch_form" action="' . $this->
object->getProvider()->getProviderUrl() .
'" method="post" target="' . $target .
'" encType="application/x-www-form-urlencoded">';
196 foreach ($launchParameters as $field => $value) {
197 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />', $field, $value) .
"\n";
200 $output .=
'</form>';
201 $output .=
'<span id ="lti_launched" style="display:none">' . $this->
lng->txt(
"launched") .
'</span>';
202 $output .=
'<script type="text/javascript">
203 function ltilaunch() {
204 document.lti_launch_form.submit();
205 document.getElementById("lti_launch_form").style.display = "none";
206 document.getElementById("lti_launched").style.display = "inline";
213 if ($this->
object->getOfflineStatus() ||
214 $this->object->isLaunchMethodEmbedded() ||
219 $user_ident = $this->cmixUser->getUsrIdent();
221 $context = $ilLTIConsumerLaunch->getContext();
222 $contextType = $ilLTIConsumerLaunch::getLTIContextType(
$context[
"type"]);
227 $this->dic->user()->getId(),
228 $this->object->getRefId(),
229 $this->object->getId()
232 $returnUrl = !$this->
object->isLaunchMethodOwnWin() ?
'' : str_replace(
238 $target = $this->
object->getLaunchMethod() ==
"newWin" ?
"_blank" :
"_self";
239 $button =
'<input class="btn btn-default ilPre" type="button" onClick="ltilaunch()" value = "' . $this->
lng->txt(
"show_content") .
'" />';
242 $output =
'<form id="lti_launch_form" name="lti_launch_form" action="' . $this->
object->getProvider()->getInitiateLogin() .
'" method="post" target="' . $target .
'" encType="application/x-www-form-urlencoded">';
245 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'target_link_uri', $this->
object->getProvider()->getProviderUrl()) .
"\n";
246 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'login_hint', $user_ident) .
"\n";
247 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'lti_message_hint',
$ltiMessageHint) .
"\n";
248 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'client_id', $this->
object->getProvider()->getClientId()) .
"\n";
249 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'lti_deployment_id', $this->
object->getProvider()->getId()) .
"\n";
250 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'launch_presentation_return_url', $returnUrl) .
"\n";
251 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'lis_result_sourcedid',
$token) .
"\n";
253 $output .=
'</form>';
254 $output .=
'<span id ="lti_launched" style="display:none">' . $this->
lng->txt(
"launched") .
'</span>';
255 $output .=
'<script type="text/javascript">
256 function ltilaunch() {
257 document.lti_launch_form.submit();
258 document.getElementById("lti_launch_form").style.display = "none";
259 document.getElementById("lti_launched").style.display = "inline";
269 $user_ident = $this->cmixUser->getUsrIdent();
271 $context = $ilLTIConsumerLaunch->getContext();
272 $contextType = $ilLTIConsumerLaunch::getLTIContextType(
$context[
"type"]);
280 $output =
'<form id="lti_launch_form" name="lti_launch_form" action="' . $this->
object->getProvider()->getInitiateLogin() .
'" method="post" target="' . $target .
'" encType="application/x-www-form-urlencoded">';
282 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'target_link_uri', $this->
object->getProvider()->getProviderUrl()) .
"\n";
283 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'login_hint', $user_ident) .
"\n";
284 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'lti_message_hint',
$ltiMessageHint) .
"\n";
285 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'client_id', $this->
object->getProvider()->getClientId()) .
"\n";
286 $output .= sprintf(
'<input type="hidden" name="%s" value="%s" />',
'lti_deployment_id', $this->
object->getProvider()->getId()) .
"\n";
287 $output .=
'</form>';
289 $output .=
"<script type=\"text/javascript\">\n" .
291 "document.lti_launch_form.submit();\n" .
304 if ($this->
object->getProvider()->getLtiVersion() ==
"LTI-1p0") {
306 $tpl =
new ilTemplate(
'tpl.lti_embedded.html',
true,
true,
'components/ILIAS/LTIConsumer');
308 $tpl->setCurrentBlock(
'launch_parameter');
309 $tpl->setVariable(
'LAUNCH_PARAMETER', $field);
310 $tpl->setVariable(
'LAUNCH_PARAM_VALUE', $value);
311 $tpl->parseCurrentBlock();
315 $tpl->setVariable(
"DELOS_CSS_HREF",
'assets/css/delos.css' . $v);
316 $tpl->setVariable(
"JQUERY_SRC",
'assets/js/jquery.js' . $v);
319 $tpl->setVariable(
'LAUNCH_URL', $this->
object->getProvider()->getProviderUrl());
321 #$DIC->ui()->mainTemplate()->getStandardTemplate();
322 #$DIC->ui()->mainTemplate()->setContent($tpl->get());
328 $this->dic->http()->saveResponse(
$response);
329 $this->dic->http()->sendResponse();
330 $this->dic->http()->close();
337 $launchContext = $ilLTIConsumerLaunch->getContext();
340 $launchContextId = (string) $launchContext[
"id"];
341 $launchContextTitle = $launchContext[
"title"];
344 $this->dic->user()->getId(),
345 $this->object->getRefId(),
346 $this->object->getId()
349 return $this->
object->buildLaunchParameters(
361 $launchContext = $ilLTIConsumerLaunch->getContext();
364 $launchContextId = (string) $launchContext[
"id"];
365 $launchContextTitle = $launchContext[
"title"];
368 $this->dic->user()->getId(),
369 $this->object->getRefId(),
370 $this->object->getId()
374 return $this->
object->buildLaunchParametersLTI13(
391 if (
$DIC->ctrl()->getNextClass() != strtolower(self::class)) {
395 if (
$DIC->ctrl()->getCmd() != self::CMD_SHOW_EMBEDDED) {
404 $this->cmixUser =
new ilCmiXapiUser($this->
object->getId(), $this->dic->user()->getId(), $this->object->getProvider()->getPrivacyIdent());
405 $user_ident = $this->cmixUser->getUsrIdent();
406 if ($user_ident ==
'' || $user_ident ==
null) {
408 $this->cmixUser->setUsrIdent($user_ident);
409 $this->cmixUser->save();
415 $scope = $loginData[
'scope'];
416 $responsetype = $loginData[
'response_type'];
417 $clientid = $loginData[
'client_id'];
418 $redirecturi = $loginData[
'redirect_uri'];
419 $loginhint = $loginData[
'login_hint'];
420 $ltimessagehint = $loginData[
'lti_message_hint'];
421 $state = $loginData[
'state'];
422 $responsemode = $loginData[
'response_mode'];
423 $nonce = $loginData[
'nonce'];
424 $prompt = $loginData[
'prompt'];
426 $ok = !empty(
$scope) && !empty($responsetype) && !empty($clientid) &&
427 !empty($redirecturi) && !empty($loginhint) &&
431 $error =
'invalid_request';
433 if ($ok && (
$scope !==
'openid')) {
435 $error =
'invalid_scope';
437 if ($ok && ($responsetype !==
'id_token')) {
439 $error =
'unsupported_response_type';
445 $error =
'invalid_request';
447 if ($this->
object->getProvider()->getClientId() !== $clientid) {
449 $error =
'unauthorized_client';
456 $this->user->getId(),
457 $this->object->getProvider()->getPrivacyIdent()
461 if ($user_ident ==
'' || $user_ident ==
null) {
467 if ((
string) $loginhint !== $user_ident) {
469 $error =
'access_denied';
472 $uris = array_map(
"trim", explode(
",", $this->
object->getProvider()->getRedirectionUris()));
473 if (!in_array($redirecturi, $uris)) {
475 $error =
'invalid_request';
479 if (isset($responsemode)) {
480 $ok = ($responsemode ===
'form_post');
482 $error =
'invalid_request';
483 $desc =
'Invalid response_mode';
487 $error =
'invalid_request';
488 $desc =
'Missing response_mode';
491 if ($ok && !empty($prompt) && ($prompt !==
'none')) {
493 $error =
'invalid_request';
494 $desc =
'Invalid prompt';
513 if (isset(
$DIC->http()->request()->getQueryParams()[$key])) {
514 return $DIC->http()->request()->getQueryParams()[$key];
517 if (isset(
$DIC->http()->request()->getParsedBody()[$key])) {
518 return $DIC->http()->request()->getParsedBody()[$key];
521 return $default ??
null;
static fillToken(int $usrId, int $refId, int $objId, int $lrsTypeId=0)
static getIdent(int $userIdentMode, ilObjUser $user)
setUsrIdent(string $usrIdent)
static isEmbeddedLaunchRequest()
getEmbeddedAutoStartFormular()
__construct(ilObjLTIConsumer $object)
validateLTI13InitalLogin(array $loginData)
getRequestValue(string $key, $default=null)
getLaunchParametersLTI13(string $endpoint, string $clientId, int $deploymentId, string $nonce)
static getLTIContextType(string $a_type)
static getIliasHttpPath()
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
special template class to simplify handling of ITX/PEAR
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
const ILIAS_VERSION_NUMERIC
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.