ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilAuthProviderLTI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 public const AUTH_MODE_PREFIX = 'lti';
31 private string $lti_context_id = "";
32 private int $ref_id = 0;
33 private ?ilLTITool $provider = null;
34 private ?array $messageParameters = null;
35
36 protected string $launchReturnUrl = "";
37
38 private ?ilLogger $logger = null;
39
44 {
46 $this->logger = ilLoggerFactory::getLogger('ltis');
47 }
48
54 public static function getAuthModeByKey(string $a_auth_key): string
55 {
56 $auth_arr = explode('_', $a_auth_key);
57 if (count($auth_arr) > 1) {
58 return 'lti_' . $auth_arr[1];
59 }
60 return 'lti';
61 }
62
68 public static function getKeyByAuthMode(string $a_auth_mode)
69 {
70 $auth_arr = explode('_', $a_auth_mode);
71 if (count($auth_arr) > 1) {
72 return ilAuthUtils::AUTH_PROVIDER_LTI . '_' . $auth_arr[1];
73 }
75 }
76
81 public static function getActiveAuthModes(): array
82 {
83 global $ilDB;
84
85 // move to connector
86 $query = 'SELECT consumer_pk from lti2_consumer where enabled = ' . $ilDB->quote(1, 'integer');
87 $res = $ilDB->query($query);
88
89 $sids = array();
90 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
91 $sids[] = $row->consumer_pk;
92 }
93 return $sids;
94 }
95
99 public static function getAuthModes(): array
100 {
101 global $ilDB;
102
103 // move to connector
104 $query = 'SELECT distinct(consumer_pk) consumer_pk from lti2_consumer';
105 $res = $ilDB->query($query);
106
107 $sids = array();
108 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
109 $sids[] = $row->consumer_pk;
110 }
111 return $sids;
112 }
113
119 public static function lookupConsumer(int $a_sid): string
120 {
121 $connector = new ilLTIDataConnector();
122 $consumer = ilLTIPlatform::fromRecordId($a_sid, $connector);
123
124 $object_ref = $consumer->getRefId();
125 $object_title = ilObject2::_lookupTitle(ilObject2::_lookupObjectId($object_ref));
126 return $consumer->getTitle() . " / " . $object_title;
127 }
128
134 public static function getServerIdByAuthMode(string $a_auth_mode): ?int
135 {
136 if (self::isAuthModeLTI($a_auth_mode)) {
137 $auth_arr = explode('_', $a_auth_mode);
138 return (int) $auth_arr[1];
139 }
140 return null;
141 }
142
148 public static function isAuthModeLTI(string $a_auth_mode): bool
149 {
150 if (!$a_auth_mode) {
151 ilLoggerFactory::getLogger('ltis')->warning('No auth mode given.');
152 return false;
153 }
154 $auth_arr = explode('_', $a_auth_mode);
155 return ($auth_arr[0] == ilAuthUtils::AUTH_PROVIDER_LTI) and $auth_arr[1];
156 }
157
163 protected function findAuthKeyId(string $a_oauth_consumer_key): int
164 {
165 global $ilDB;
166
167 $query = 'SELECT consumer_pk from lti2_consumer where consumer_key = ' . $ilDB->quote(
168 $a_oauth_consumer_key,
169 'text'
170 );
171 // $query = 'SELECT id from lti_ext_consumer where consumer_key = '.$ilDB->quote($a_oauth_consumer_key,'text');
172 $this->getLogger()->debug($query);
173 $res = $ilDB->query($query);
174
175 $lti_id = 0;
176 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
177 $lti_id = $row->consumer_pk;
178 // $lti_id = $row->id;
179 }
180 $this->getLogger()->debug('External consumer key is: ' . (int) $lti_id);
181 return $lti_id;
182 }
183
189 protected function findAuthPrefix(int $a_lti_id): string
190 {
191 global $ilDB;
192
193 $query = 'SELECT prefix from lti_ext_consumer where id = ' . $ilDB->quote($a_lti_id, 'integer');
194 $this->getLogger()->debug($query);
195 $res = $ilDB->query($query);
196
197 // $prefix = 'lti'.$a_lti_id.'_';
198 $prefix = '';
199 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
200 $prefix = $row->prefix;
201 }
202 $this->getLogger()->debug('LTI prefix: ' . $prefix);
203 return $prefix;
204 }
205
211 protected function findGlobalRole(int $a_lti_id): ?int
212 {
213 global $ilDB;
214
215 $query = 'SELECT role from lti_ext_consumer where id = ' . $ilDB->quote($a_lti_id, 'integer');
216 $this->getLogger()->debug($query);
217 $res = $ilDB->query($query);
218
219 $role = null;
220 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
221 $role = (int) $row->role;
222 }
223 $this->getLogger()->debug('LTI role: ' . $role);
224 return $role;
225 }
226
234 public function doAuthentication(\ilAuthStatus $status): bool
235 {
236 global $DIC;
237 $post = [];
238
239 $lti_provider = new ilLTITool(new ilLTIDataConnector());
240
241 if ($DIC->http()->wrapper()->post()->has('launch_presentation_return_url')) {
242 $this->launchReturnUrl = $DIC->http()->wrapper()->post()->retrieve('launch_presentation_return_url', $DIC->refinery()->kindlyTo()->string());
243 setcookie("launch_presentation_return_url", $this->launchReturnUrl, time() + 86400, "/", "", true, true);
244 $this->logger->info("Setting launch_presentation_return_url in cookie storage " . $this->launchReturnUrl);
245 }
246 $lti_provider->handleRequest();
247 $this->provider = $lti_provider;
248 $this->messageParameters = $this->provider->getMessageParameters();
249
250 if (!$DIC->http()->wrapper()->post()->has('launch_presentation_return_url')) {
251 $this->launchReturnUrl = $_COOKIE['launch_presentation_return_url'] ?? "";
252 $this->logger->info("Catching launch_presentation_return_url from cookies" . $this->launchReturnUrl);
253 $post["launch_presentation_return_url"] = $this->launchReturnUrl;
254 }
255
256 if (!$lti_provider->ok) {
257 $this->getLogger()->info('LTI authentication failed with message: ' . $lti_provider->reason);
258 $status->setReason($lti_provider->reason);
260 return false;
261 } else {
262 $this->getLogger()->debug('LTI authentication success');
263 }
264
265 if (empty($this->messageParameters)) {
266 $status->setReason('empty_lti_message_parameters');
268 return false;
269 }
270
271 $platform = ilLTIPlatform::fromConsumerKey($this->provider->platform->getKey(), $this->provider->platform->getDataConnector());
272 ilSession::clear("lti_context_ids");
273 $this->ref_id = $platform->getRefId();
274
275 $lti_context_ids = ilSession::get('lti_context_ids');
276
277 if (isset($lti_context_ids) && is_array($lti_context_ids)) {
278 if (!in_array($this->ref_id, $lti_context_ids)) {
279 $this->getLogger()->debug("push new lti ref_id: " . $this->ref_id);
280 $lti_context_ids[] = $this->ref_id;
281 ilSession::set('lti_context_ids', $lti_context_ids);
282 $this->getLogger()->debug((string) var_export(ilSession::get('lti_context_ids'), true));
283 }
284 } else {
285 $this->getLogger()->debug("lti_context_ids is not set. Create new array...");
286 ilSession::set('lti_context_ids', [$this->ref_id]);
287 $this->getLogger()->debug((string) var_export(ilSession::get('lti_context_ids'), true));
288 }
289
290 if (!empty($this->messageParameters['launch_presentation_return_url'])) {
291 $post['launch_presentation_return_url'] = $this->messageParameters['launch_presentation_return_url'];
292 }
293 if (!empty($this->messageParameters['launch_presentation_css_url'])) {
294 $post['launch_presentation_css_url'] = $this->messageParameters['launch_presentation_css_url'];
295 }
296 if (!empty($this->messageParameters['resource_link_title'])) {
297 $post['resource_link_title'] = $this->messageParameters['resource_link_title'];
298 }
299
300 ilSession::set('lti_' . $this->ref_id . '_post_data', $post);
301
303 $obj_definition = $DIC["objDefinition"];
304
305 ilSession::set('lti_init_target', $obj_definition->getClassName(ilObject::_lookupType($this->ref_id, true)) . '_' . $this->ref_id);
306
307 if (!$platform->enabled) {
308 $this->getLogger()->warning('Consumer is not enabled');
309 $status->setReason('lti_consumer_inactive');
311 return false;
312 }
313
314 if (!$platform->getActive()) {
315 $this->getLogger()->warning('Consumer is not active');
316 $status->setReason('lti_consumer_inactive');
318 return false;
319 }
320
321 $lti_id = $platform->getExtConsumerId();
322 if (!$lti_id) {
323 $status->setReason('lti_auth_failed_invalid_key');
325 return false;
326 }
327
328 $this->getLogger()->debug('Using prefix:' . $platform->getPrefix());
329
330 $this->getCredentials()->setUsername($this->messageParameters['user_id']);
331
332 $internal_account = $this->findUserId(
333 $this->getCredentials()->getUsername(),
334 (string) $lti_id,
335 $platform->getPrefix()
336 );
337
338 if ($internal_account) {
339 $this->updateUser($internal_account, $platform);
340 } else {
341 $internal_account = $this->createUser($platform);
342 }
343
344 $this->handleLocalRoleAssignments($internal_account, $platform, $this->ref_id);
345
347 $status->setAuthenticatedUserId($internal_account);
348
349 return true;
350 }
351
359 protected function findUserId(string $a_oauth_user, string $a_oauth_id, string $a_user_prefix): int
360 {
362 self::AUTH_MODE_PREFIX . '_' . $a_oauth_id,
363 $a_oauth_user
364 );
365 $user_id = 0;
366 if ($user_name) {
367 $user_id = ilObjUser::_lookupId($user_name);
368 }
369 $this->getLogger()->debug('Found user with auth mode lti_' . $a_oauth_id . ' with user_id: ' . $user_id);
370 return $user_id;
371 }
372
380 protected function updateUser(int $a_local_user_id, ilLTIPlatform $consumer): int
381 {
382 global $ilClientIniFile, $DIC;
383 // if (empty($this->messageParameters)) {
384 // $status->setReason('empty_lti_message_parameters');
385 // $status->setStatus(ilAuthStatus::STATUS_AUTHENTICATION_FAILED);
386 // return false;
387 // }
388 $user_obj = new ilObjUser($a_local_user_id);
389 if (isset($this->messageParameters['lis_person_name_given'])) {
390 $user_obj->setFirstname($this->messageParameters['lis_person_name_given']);
391 } else {
392 $user_obj->setFirstname('-');
393 }
394 if (isset($this->messageParameters['lis_person_name_family'])) {
395 $user_obj->setLastname($this->messageParameters['lis_person_name_family']);
396 } else {
397 $user_obj->setLastname('-');
398 }
399 $user_obj->setEmail($this->messageParameters['lis_person_contact_email_primary']);
400
401 $user_obj->setActive(true);
402
403 $until = $user_obj->getTimeLimitUntil();
404
405 if ($until < (time() + (int) $ilClientIniFile->readVariable('session', 'expire'))) {
406 $user_obj->setTimeLimitFrom(time() - 60);
407 $user_obj->setTimeLimitUntil(time() + (int) $ilClientIniFile->readVariable("session", "expire"));
408 }
409 $user_obj->refreshLogin();
410 $user_obj->update();
411
412 $GLOBALS['DIC']->rbac()->admin()->assignUser($consumer->getRole(), $user_obj->getId());
413 $this->getLogger()->debug('Assigned user to: ' . $consumer->getRole());
414
415 $this->getLogger()->info('Update of lti user with uid: ' . $user_obj->getId() . ' and login: ' . $user_obj->getLogin());
416 return $user_obj->getId();
417 }
418
427 protected function createUser(ilLTIPlatform $consumer): int
428 {
429 global $ilClientIniFile, $DIC;
430 // if (empty($this->messageParameters)) {
431 // $status->setReason('empty_lti_message_parameters');
432 // $status->setStatus(ilAuthStatus::STATUS_AUTHENTICATION_FAILED);
433 // return false;
434 // }
435 $userObj = new ilObjUser();
436 $local_user = ilAuthUtils::_generateLogin($consumer->getPrefix() . '_' . $this->getCredentials()->getUsername());
437
438 $newUser["login"] = $local_user;
439 if (isset($this->messageParameters['lis_person_name_given'])) {
440 $newUser["firstname"] = $this->messageParameters['lis_person_name_given'];
441 } else {
442 $newUser["firstname"] = '-';
443 }
444 if (isset($this->messageParameters['lis_person_name_family'])) {
445 $newUser["lastname"] = $this->messageParameters['lis_person_name_family'];
446 } else {
447 $newUser["lastname"] = '-';
448 }
449 $newUser['email'] = $this->messageParameters['lis_person_contact_email_primary'];
450
451 // set "plain md5" password (= no valid password)
452 // $newUser["passwd"] = "";
453 $newUser["passwd_type"] = ilObjUser::PASSWD_CRYPTED;
454
455 $newUser["auth_mode"] = 'lti_' . $consumer->getExtConsumerId();
456 $newUser['ext_account'] = $this->getCredentials()->getUsername();
457 $newUser["profile_incomplete"] = 0;
458
459 // ILIAS 8
460 //check
461 $newUser["gender"] = 'n';
462 $newUser["title"] = null;
463 $newUser["birthday"] = null;
464 $newUser["institution"] = null;
465 $newUser["department"] = null;
466 $newUser["street"] = null;
467 $newUser["city"] = null;
468 $newUser["zipcode"] = null;
469 $newUser["country"] = null;
470 $newUser["sel_country"] = null;
471 $newUser["phone_office"] = null;
472 $newUser["phone_home"] = null;
473 $newUser["phone_mobile"] = null;
474 $newUser["fax"] = null;
475 $newUser["matriculation"] = null;
476 $newUser["second_email"] = null;
477 $newUser["hobby"] = null;
478 $newUser["client_ip"] = null;
479 $newUser["passwd_salt"] = null;//$newUser->getPasswordSalt();
480 $newUser["latitude"] = null;
481 $newUser["longitude"] = null;
482 $newUser["loc_zoom"] = null;
483 $newUser["last_login"] = null;
484 $newUser["first_login"] = null;
485 $newUser["last_profile_prompt"] = null;
486 $newUser["last_update"] = ilUtil::now();
487 $newUser["create_date"] = ilUtil::now();
488 $newUser["referral_comment"] = null;
489 $newUser["approve_date"] = null;
490 $newUser["agree_date"] = null;
491 $newUser["inactivation_date"] = null;
492 $newUser["time_limit_from"] = null;
493 $newUser["time_limit_until"] = null;
494 $newUser["is_self_registered"] = null;
495 //end to check
496
497 $newUser["passwd_enc_type"] = "";
498 $newUser["active"] = true;
499 $newUser["time_limit_owner"] = 7;
500 $newUser["time_limit_unlimited"] = 0;
501 $newUser["time_limit_message"] = 0;
502 $newUser["passwd"] = " ";
503 // $newUser["last_update"]
504
505 // system data
506 $userObj->assignData($newUser);
507 $userObj->setTitle($userObj->getFullname());
508 $userObj->setDescription($userObj->getEmail());
509
510 // set user language
511 $userObj->setLanguage($consumer->getLanguage());
512
513 // Time limit
514 $userObj->setTimeLimitOwner(7);
515 $userObj->setTimeLimitUnlimited(false);
516 $userObj->setTimeLimitFrom(time() - 5);
517 // todo ?
518 $userObj->setTimeLimitUntil(time() + (int) $ilClientIniFile->readVariable("session", "expire"));
519
520 // Create user in DB
521 $userObj->setOwner(6);
522 $userObj->create();
523 $userObj->setActive(true);
524 // $userObj->updateOwner();
525 $userObj->setLastPasswordChangeTS(time());
526 $userObj->saveAsNew();
527 $userObj->writePrefs();
528
529 $GLOBALS['DIC']->rbac()->admin()->assignUser($consumer->getRole(), $userObj->getId());
530
531 $this->getLogger()->info('Created new lti user with uid: ' . $userObj->getId() . ' and login: ' . $userObj->getLogin());
532 return $userObj->getId();
533 }
534
535 protected function handleLocalRoleAssignments(int $user_id, ilLTIPlatform $consumer, int $target_ref_id, ?int $default_rol_id = null): bool
536 {
537 global $DIC;
538 $this->getLogger()->info('$target_ref_id: ' . $target_ref_id);
539 if (!$target_ref_id) {
540 $this->getLogger()->warning('No target id given');
541 return false;
542 }
543
544 $obj_settings = new ilLTIProviderObjectSetting($target_ref_id, $consumer->getExtConsumerId());
545
546 $roles = $this->messageParameters['roles'] ?? '';
547
548 if (!is_string($roles) || empty($roles)) {
549 $this->getLogger()->warning('No role information given or invalid role format.');
550 return false;
551 }
552
553 $this->getLogger()->info("Deassigning all roles for user: " . $user_id);
554 $DIC->rbac()->admin()->deassignUser($obj_settings->getTutorRole(), $user_id);
555 $DIC->rbac()->admin()->deassignUser($obj_settings->getMemberRole(), $user_id);
556 $DIC->rbac()->admin()->deassignUser($obj_settings->getAdminRole(), $user_id);
557
558 $role_arr = is_array($roles) ? $roles : explode(',', $roles);
559
560 $this->getLogger()->info('Recieved roles: ' . implode(', ', $role_arr));
561
562 $tree = $DIC->repositoryTree();
563 $parent = $tree->getParentId($target_ref_id);
564 if ($parent != 1) {
565 $this->handleLocalRoleAssignments($user_id, $consumer, $parent, $obj_settings->getMemberRole());
566 }
567 foreach ($role_arr as $role) {
568 $role = trim($role);
569 $local_role_id = $this->mapLTIRoleToLocalRole($role, $obj_settings) == 0 && $default_rol_id != null ? $default_rol_id : $this->mapLTIRoleToLocalRole($role, $obj_settings);
570 if (isset($local_role_id)) {
571 $this->getLogger()->info('Assigning local role ID: ' . $local_role_id . ' for LTI role: ' . $role . ' to user ID: ' . $user_id);
572 $DIC->rbac()->admin()->assignUser($local_role_id, $user_id);
573 } else {
574 $this->getLogger()->info('No local role mapping found for LTI role: ' . $role);
575 }
576 }
577
578 return true;
579 }
580
588 protected function mapLTIRoleToLocalRole(string $lti_role, ilLTIProviderObjectSetting $settings): ?int
589 {
590 // Prioritize more specific roles (sub-roles)
591 $role_map = [
592 // System Roles
593 'http://purl.imsglobal.org/vocab/lti/system/person#TestUser' => null, // Example: No mapping for TestUser
594 'http://purl.imsglobal.org/vocab/lis/v2/system/person#Administrator' => $settings->getAdminRole(),
595 'http://purl.imsglobal.org/vocab/lis/v2/system/person#None' => null,
596 'http://purl.imsglobal.org/vocab/lis/v2/system/person#AccountAdmin' => null, // No direct mapping
597 'http://purl.imsglobal.org/vocab/lis/v2/system/person#Creator' => null, // No direct mapping
598 'http://purl.imsglobal.org/vocab/lis/v2/system/person#SysAdmin' => null, // No direct mapping
599 'http://purl.imsglobal.org/vocab/lis/v2/system/person#SysSupport' => null, // No direct mapping
600 'http://purl.imsglobal.org/vocab/lis/v2/system/person#User' => null, // No direct mapping
601
602 // Institution Roles
603 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator' => $settings->getAdminRole(),
604 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Faculty' => $settings->getTutorRole(),
605 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Guest' => null, // No direct mapping
606 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#None' => null,
607 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Other' => null, // No direct mapping
608 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Staff' => null, // No direct mapping
609 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Student' => $settings->getMemberRole(),
610 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Alumni' => null, // No direct mapping
611 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Instructor' => $settings->getTutorRole(),
612 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Learner' => $settings->getMemberRole(),
613 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Member' => $settings->getMemberRole(),
614 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Mentor' => null, // No direct mapping
615 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Observer' => null, // No direct mapping
616 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#ProspectiveStudent' => null, // No direct mapping
617
618 // Context Roles (Main)
619 'http://purl.imsglobal.org/vocab/lis/v2/membership#Administrator' => $settings->getAdminRole(),
620 'http://purl.imsglobal.org/vocab/lis/v2/membership#ContentDeveloper' => null, // No direct mapping
621 'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor' => $settings->getTutorRole(),
622 'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner' => $settings->getMemberRole(),
623 'http://purl.imsglobal.org/vocab/lis/v2/membership#Mentor' => null, // No direct mapping
624 'http://purl.imsglobal.org/vocab/lis/v2/membership#Manager' => $settings->getAdminRole(), // Potentially map to admin
625 'http://purl.imsglobal.org/vocab/lis/v2/membership#Member' => $settings->getMemberRole(),
626 'http://purl.imsglobal.org/vocab/lis/v2/membership#Officer' => null, // No direct mapping
627
628 // Context Sub-Roles (TeachingAssistant)
629 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#TeachingAssistant' => $settings->getTutorRole(),
630 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#TeachingAssistantGroup' => $settings->getTutorRole(),
631 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#TeachingAssistantOffering' => $settings->getTutorRole(),
632 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#TeachingAssistantSection' => $settings->getTutorRole(),
633 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#TeachingAssistantSectionAssociation' => $settings->getTutorRole(),
634 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#TeachingAssistantTemplate' => $settings->getTutorRole(),
635 // Context Sub-Roles (Grader)
636 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#Grader' => $settings->getTutorRole(), // Map Grader to Tutor
637 // Context Sub-Roles (GuestInstructor, Lecturer, PrimaryInstructor, SecondaryInstructor)
638 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#GuestInstructor' => $settings->getTutorRole(),
639 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#Lecturer' => $settings->getTutorRole(),
640 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#PrimaryInstructor' => $settings->getTutorRole(),
641 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#SecondaryInstructor' => $settings->getTutorRole(),
642 // Context Sub-Roles (ExternalInstructor)
643 'http://purl.imsglobal.org/vocab/lis/v2/membership/Instructor#ExternalInstructor' => $settings->getTutorRole(),
644
645 // Context Sub-Roles (ExternalLearner, GuestLearner, Learner, NonCreditLearner)
646 'http://purl.imsglobal.org/vocab/lis/v2/membership/Learner#ExternalLearner' => $settings->getMemberRole(),
647 'http://purl.imsglobal.org/vocab/lis/v2/membership/Learner#GuestLearner' => $settings->getMemberRole(),
648 'http://purl.imsglobal.org/vocab/lis/v2/membership/Learner#Learner' => $settings->getMemberRole(),
649 'http://purl.imsglobal.org/vocab/lis/v2/membership/Learner#NonCreditLearner' => $settings->getMemberRole(),
650
651 // Context Sub-Roles (AreaManager, CourseCoordinator, ExternalObserver, Manager, Observer)
652 'http://purl.imsglobal.org/vocab/lis/v2/membership/Manager#AreaManager' => $settings->getAdminRole(),
653 'http://purl.imsglobal.org/vocab/lis/v2/membership/Manager#CourseCoordinator' => null,
654 'http://purl.imsglobal.org/vocab/lis/v2/membership/Manager#ExternalObserver' => null,
655 'http://purl.imsglobal.org/vocab/lis/v2/membership/Manager#Manager' => $settings->getAdminRole(),
656 'http://purl.imsglobal.org/vocab/lis/v2/membership/Manager#Observer' => null,
657
658 // Context Sub-Roles (Advisor, Auditor, ExternalAdvisor, ExternalAuditor, ExternalLearningFacilitator, ExternalMentor, ExternalReviewer, ExternalTutor, LearningFacilitator, Mentor, Reviewer, Tutor)
659 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#Advisor' => null,
660 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#Auditor' => null,
661 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#ExternalAdvisor' => null,
662 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#ExternalAuditor' => null,
663 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#ExternalLearningFacilitator' => null,
664 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#ExternalMentor' => null,
665 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#ExternalReviewer' => null,
666 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#ExternalTutor' => null,
667 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#LearningFacilitator' => null,
668 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#Mentor' => null,
669 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#Reviewer' => null,
670 'http://purl.imsglobal.org/vocab/lis/v2/membership/Mentor#Tutor' => $settings->getTutorRole(), // Map Tutor to Tutor
671
672 // Context Sub-Roles (Chair, Communications, Secretary, Treasurer, Vice-Chair)
673 'http://purl.imsglobal.org/vocab/lis/v2/membership/Officer#Chair' => null,
674 'http://purl.imsglobal.org/vocab/lis/v2/membership/Officer#Communications' => null,
675 'http://purl.imsglobal.org/vocab/lis/v2/membership/Officer#Secretary' => null,
676 'http://purl.imsglobal.org/vocab/lis/v2/membership/Officer#Treasurer' => null,
677 'http://purl.imsglobal.org/vocab/lis/v2/membership/Officer#Vice-Chair' => null,
678
679 // Context Sub-Roles (ContentDeveloper, ContentExpert, ExternalContentExpert, Librarian)
680 'http://purl.imsglobal.org/vocab/lis/v2/membership/ContentDeveloper#ContentDeveloper' => null,
681 'http://purl.imsglobal.org/vocab/lis/v2/membership/ContentDeveloper#ContentExpert' => null,
682 'http://purl.imsglobal.org/vocab/lis/v2/membership/ContentDeveloper#ExternalContentExpert' => null,
683 'http://purl.imsglobal.org/vocab/lis/v2/membership/ContentDeveloper#Librarian' => null,
684
685 // Context Sub-Roles (Member)
686 'http://purl.imsglobal.org/vocab/lis/v2/membership/Member#Member' => $settings->getMemberRole(),
687
688 // Context Sub-Roles (Administrator, Developer, ExternalDeveloper, ExternalSupport, ExternalSystemAdministrator, Support, SystemAdministrator)
689 'http://purl.imsglobal.org/vocab/lis/v2/membership/Administrator#Administrator' => $settings->getAdminRole(),
690 'http://purl.imsglobal.org/vocab/lis/v2/membership/Administrator#Developer' => null,
691 'http://purl.imsglobal.org/vocab/lis/v2/membership/Administrator#ExternalDeveloper' => null,
692 'http://purl.imsglobal.org/vocab/lis/v2/membership/Administrator#ExternalSupport' => null,
693 'http://purl.imsglobal.org/vocab/lis/v2/membership/Administrator#ExternalSystemAdministrator' => null,
694 'http://purl.imsglobal.org/vocab/lis/v2/membership/Administrator#Support' => null,
695 'http://purl.imsglobal.org/vocab/lis/v2/membership/Administrator#SystemAdministrator' => null,
696 ];
697
698 // LTI 1.0/1.1 simple names (supported for backward compatibility)
699 $simple_name_map = [
700 'Instructor' => $settings->getTutorRole(),
701 'Learner' => $settings->getMemberRole(),
702 'ContentDeveloper' => null,
703 'Administrator' => $settings->getAdminRole(),
704 'Mentor' => null,
705 'Manager' => $settings->getAdminRole(),
706 'Member' => $settings->getMemberRole(),
707 'Officer' => null,
708 ];
709
710
711 if (isset($role_map[$lti_role])) {
712 return $role_map[$lti_role];
713 } elseif (isset($simple_name_map[$lti_role])) {
714 // Check for simple names
715 return $simple_name_map[$lti_role];
716 }
717
718 return null;
719 }
720
721}
OAuth based lti authentication.
static getServerIdByAuthMode(string $a_auth_mode)
Get auth id by auth mode.
static getActiveAuthModes()
get all active authmode server ids
findAuthKeyId(string $a_oauth_consumer_key)
find consumer key id
static getKeyByAuthMode(string $a_auth_mode)
Get auth id by auth mode.
__construct(ilAuthCredentials $credentials)
Constructor.
static lookupConsumer(int $a_sid)
Lookup consumer title.
static getAuthModeByKey(string $a_auth_key)
Get auth mode by key.
createUser(ilLTIPlatform $consumer)
create new user @access protected
findAuthPrefix(int $a_lti_id)
find lti id
ilLTIDataConnector $dataConnector
mapLTIRoleToLocalRole(string $lti_role, ilLTIProviderObjectSetting $settings)
Maps an LTI role (URI or simple name) to a local ILIAS role ID.
findUserId(string $a_oauth_user, string $a_oauth_id, string $a_user_prefix)
Find user by auth mode and lti id.
handleLocalRoleAssignments(int $user_id, ilLTIPlatform $consumer, int $target_ref_id, ?int $default_rol_id=null)
updateUser(int $a_local_user_id, ilLTIPlatform $consumer)
update existing user @access protected
static isAuthModeLTI(string $a_auth_mode)
Check if user auth mode is LTI.
findGlobalRole(int $a_lti_id)
find global role of consumer
ilAuthCredentials $credentials
const int STATUS_AUTHENTICATION_FAILED
setReason(string $a_reason)
Set reason.
setAuthenticatedUserId(int $a_id)
setStatus(int $a_status)
Set auth status.
const int STATUS_AUTHENTICATED
static _generateLogin(string $a_login)
generate free login by starting with a default string and adding postfix numbers
const int AUTH_PROVIDER_LTI
const FETCHMODE_OBJECT
LTI provider for LTI launch.
static fromRecordId(int|string $id, DataConnector $dataConnector)
Load the platform from the database by its record ID.
static fromConsumerKey(?string $key=null, $dataConnector=null, bool $autoEnable=false)
Load the platform from the database by its consumer key.
LTI provider for LTI launch.
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
User class.
const PASSWD_CRYPTED
static _lookupId(string|array $a_user_str)
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
static now()
Return current timestamp in Y-m-d H:i:s format.
doAuthentication(ilAuthStatus $status)
$res
Definition: ltiservices.php:69
$post
Definition: ltitoken.php:46
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54
$_COOKIE[session_name()]
Definition: xapitoken.php:52