ILIAS  release_8 Revision v8.24
ilAuthProviderLTI Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilAuthProviderLTI:
+ Collaboration diagram for ilAuthProviderLTI:

Static Public Member Functions

static getAuthModeByKey (string $a_auth_key)
 Get auth mode by key. More...
 
static getKeyByAuthMode (string $a_auth_mode)
 Get auth id by auth mode. More...
 
static getActiveAuthModes ()
 get all active authmode server ids More...
 
static getAuthModes ()
 
static lookupConsumer (int $a_sid)
 Lookup consumer title. More...
 
static getServerIdByAuthMode (string $a_auth_mode)
 Get auth id by auth mode. More...
 
static isAuthModeLTI (string $a_auth_mode)
 Check if user auth mode is LTI. More...
 

Data Fields

const AUTH_MODE_PREFIX = 'lti'
 

Protected Member Functions

 findAuthKeyId (string $a_oauth_consumer_key)
 find consumer key id More...
 
 findAuthPrefix (int $a_lti_id)
 find lti id More...
 
 findGlobalRole (int $a_lti_id)
 find global role of consumer More...
 
 findUserId (string $a_oauth_user, string $a_oauth_id, string $a_user_prefix)
 Find user by auth mode and lti id. More...
 
 updateUser (int $a_local_user_id, ilLTIPlatform $consumer)
 update existing user @access protected More...
 
 createUser (ilLTIPlatform $consumer)
 create new user @access protected More...
 
 handleLocalRoleAssignments (int $user_id, ilLTIPlatform $consumer)
 
- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, string $a_reason)
 Handle failed authentication. More...
 

Private Attributes

ilLTIDataConnector $dataConnector = null
 
string $lti_context_id = ""
 
int $ref_id = 0
 
ilLTITool $provider = null
 
array $messageParameters = null
 

Additional Inherited Members

- Public Member Functions inherited from ilAuthProvider
 __construct (ilAuthCredentials $credentials)
 Constructor. More...
 
 getLogger ()
 Get logger. More...
 
 getCredentials ()
 
- Public Member Functions inherited from ilAuthProviderInterface
 doAuthentication (\ilAuthStatus $status)
 Do authentication. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning OAuth based lti authentication

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Uwe Kohnle kohnl.nosp@m.e@in.nosp@m.terne.nosp@m.tleh.nosp@m.rer-g.nosp@m.mbh..nosp@m.de
Stefan Schneider

Definition at line 27 of file class.ilAuthProviderLTI.php.

Member Function Documentation

◆ createUser()

ilAuthProviderLTI::createUser ( ilLTIPlatform  $consumer)
protected

create new user @access protected

Parameters
ilLTIPlatform$consumer
Returns
int
Exceptions
ilPasswordException
ilUserException

Definition at line 418 of file class.ilAuthProviderLTI.php.

418 : int
419 {
420 global $ilClientIniFile, $DIC;
421 // if (empty($this->messageParameters)) {
422 // $status->setReason('empty_lti_message_parameters');
423 // $status->setStatus(ilAuthStatus::STATUS_AUTHENTICATION_FAILED);
424 // return false;
425 // }
426 $userObj = new ilObjUser();
427 $local_user = ilAuthUtils::_generateLogin($consumer->getPrefix() . '_' . $this->getCredentials()->getUsername());
428
429 $newUser["login"] = $local_user;
430 if(isset($this->messageParameters['lis_person_name_given'])) {
431 $newUser["firstname"] = $this->messageParameters['lis_person_name_given'];
432 } else {
433 $newUser["firstname"] = '-';
434 }
435 if(isset($this->messageParameters['lis_person_name_family'])) {
436 $newUser["lastname"] = $this->messageParameters['lis_person_name_family'];
437 } else {
438 $newUser["lastname"] = '-';
439 }
440 $newUser['email'] = $this->messageParameters['lis_person_contact_email_primary'];
441
442 // set "plain md5" password (= no valid password)
443 // $newUser["passwd"] = "";
444 $newUser["passwd_type"] = ilObjUser::PASSWD_CRYPTED;
445
446 $newUser["auth_mode"] = 'lti_' . $consumer->getExtConsumerId();
447 $newUser['ext_account'] = $this->getCredentials()->getUsername();
448 $newUser["profile_incomplete"] = 0;
449
450 // ILIAS 8
451 //check
452 $newUser["gender"] = 'n';
453 $newUser["title"] = null;
454 $newUser["birthday"] = null;
455 $newUser["institution"] = null;
456 $newUser["department"] = null;
457 $newUser["street"] = null;
458 $newUser["city"] = null;
459 $newUser["zipcode"] = null;
460 $newUser["country"] = null;
461 $newUser["sel_country"] = null;
462 $newUser["phone_office"] = null;
463 $newUser["phone_home"] = null;
464 $newUser["phone_mobile"] = null;
465 $newUser["fax"] = null;
466 $newUser["matriculation"] = null;
467 $newUser["second_email"] = null;
468 $newUser["hobby"] = null;
469 $newUser["client_ip"] = null;
470 $newUser["passwd_salt"] = null;//$newUser->getPasswordSalt();
471 $newUser["latitude"] = null;
472 $newUser["longitude"] = null;
473 $newUser["loc_zoom"] = null;
474 $newUser["last_login"] = null;
475 $newUser["first_login"] = null;
476 $newUser["last_profile_prompt"] = null;
477 $newUser["last_update"] = ilUtil::now();
478 $newUser["create_date"] = ilUtil::now();
479 $newUser["referral_comment"] = null;
480 $newUser["approve_date"] = null;
481 $newUser["agree_date"] = null;
482 $newUser["inactivation_date"] = null;
483 $newUser["time_limit_from"] = null;
484 $newUser["time_limit_until"] = null;
485 $newUser["is_self_registered"] = null;
486 //end to check
487
488 $newUser["passwd_enc_type"] = "";
489 $newUser["active"] = true;
490 $newUser["time_limit_owner"] = 7;
491 $newUser["time_limit_unlimited"] = 0;
492 $newUser["time_limit_message"] = 0;
493 $newUser["passwd"] = " ";
494 // $newUser["last_update"]
495
496 // system data
497 $userObj->assignData($newUser);
498 $userObj->setTitle($userObj->getFullname());
499 $userObj->setDescription($userObj->getEmail());
500
501 // set user language
502 $userObj->setLanguage($consumer->getLanguage());
503
504 // Time limit
505 $userObj->setTimeLimitOwner(7);
506 $userObj->setTimeLimitUnlimited(false);
507 $userObj->setTimeLimitFrom(time() - 5);
508 // todo ?
509 $userObj->setTimeLimitUntil(time() + (int) $ilClientIniFile->readVariable("session", "expire"));
510
511 // Create user in DB
512 $userObj->setOwner(6);
513 $userObj->create();
514 $userObj->setActive(true);
515 // $userObj->updateOwner();
516 $userObj->setLastPasswordChangeTS(time());
517 $userObj->saveAsNew();
518 $userObj->writePrefs();
519
520 $GLOBALS['DIC']->rbac()->admin()->assignUser($consumer->getRole(), $userObj->getId());
521
522 $this->getLogger()->info('Created new lti user with uid: ' . $userObj->getId() . ' and login: ' . $userObj->getLogin());
523 return $userObj->getId();
524 }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
getLogger()
Get logger.
static _generateLogin(string $a_login)
generate free login by starting with a default string and adding postfix numbers
User class.
const PASSWD_CRYPTED
static now()
Return current timestamp in Y-m-d H:i:s format.
global $DIC
Definition: feed.php:28

References $DIC, $GLOBALS, ilAuthUtils\_generateLogin(), ilAuthProvider\getCredentials(), ilLTIPlatform\getExtConsumerId(), ilLTIPlatform\getLanguage(), ilAuthProvider\getLogger(), ilLTIPlatform\getPrefix(), ilLTIPlatform\getRole(), ilUtil\now(), and ilObjUser\PASSWD_CRYPTED.

+ Here is the call graph for this function:

◆ findAuthKeyId()

ilAuthProviderLTI::findAuthKeyId ( string  $a_oauth_consumer_key)
protected

find consumer key id

Parameters
string$a_oauth_consumer_key
Returns
int

Definition at line 147 of file class.ilAuthProviderLTI.php.

147 : int
148 {
149 global $ilDB;
150
151 $query = 'SELECT consumer_pk from lti2_consumer where consumer_key = ' . $ilDB->quote(
152 $a_oauth_consumer_key,
153 'text'
154 );
155 // $query = 'SELECT id from lti_ext_consumer where consumer_key = '.$ilDB->quote($a_oauth_consumer_key,'text');
156 $this->getLogger()->debug($query);
157 $res = $ilDB->query($query);
158
159 $lti_id = 0;
160 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
161 $lti_id = $row->consumer_pk;
162 // $lti_id = $row->id;
163 }
164 $this->getLogger()->debug('External consumer key is: ' . (int) $lti_id);
165 return $lti_id;
166 }
$res
Definition: ltiservices.php:69
$query

References $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ilAuthProvider\getLogger().

+ Here is the call graph for this function:

◆ findAuthPrefix()

ilAuthProviderLTI::findAuthPrefix ( int  $a_lti_id)
protected

find lti id

Parameters
int$a_lti_id
Returns
string

Definition at line 173 of file class.ilAuthProviderLTI.php.

173 : string
174 {
175 global $ilDB;
176
177 $query = 'SELECT prefix from lti_ext_consumer where id = ' . $ilDB->quote($a_lti_id, 'integer');
178 $this->getLogger()->debug($query);
179 $res = $ilDB->query($query);
180
181 // $prefix = 'lti'.$a_lti_id.'_';
182 $prefix = '';
183 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
184 $prefix = $row->prefix;
185 }
186 $this->getLogger()->debug('LTI prefix: ' . $prefix);
187 return $prefix;
188 }

References $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ilAuthProvider\getLogger().

+ Here is the call graph for this function:

◆ findGlobalRole()

ilAuthProviderLTI::findGlobalRole ( int  $a_lti_id)
protected

find global role of consumer

Parameters
int$a_lti_id
Returns
int|null

Definition at line 195 of file class.ilAuthProviderLTI.php.

195 : ?int
196 {
197 global $ilDB;
198
199 $query = 'SELECT role from lti_ext_consumer where id = ' . $ilDB->quote($a_lti_id, 'integer');
200 $this->getLogger()->debug($query);
201 $res = $ilDB->query($query);
202
203 $role = null;
204 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
205 $role = (int) $row->role;
206 }
207 $this->getLogger()->debug('LTI role: ' . $role);
208 return $role;
209 }

References $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, ilAuthProvider\getLogger(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ findUserId()

ilAuthProviderLTI::findUserId ( string  $a_oauth_user,
string  $a_oauth_id,
string  $a_user_prefix 
)
protected

Find user by auth mode and lti id.

Parameters
string$a_oauth_user
string$a_oauth_id
string$a_user_prefix
Returns
int

Definition at line 350 of file class.ilAuthProviderLTI.php.

350 : int
351 {
353 self::AUTH_MODE_PREFIX . '_' . $a_oauth_id,
354 $a_oauth_user
355 );
356 $user_id = 0;
357 if ($user_name) {
358 $user_id = ilObjUser::_lookupId($user_name);
359 }
360 $this->getLogger()->debug('Found user with auth mode lti_' . $a_oauth_id . ' with user_id: ' . $user_id);
361 return $user_id;
362 }
static _lookupId($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

References ilAuthProvider\$user_id, ilObjUser\_checkExternalAuthAccount(), ilObjUser\_lookupId(), and ilAuthProvider\getLogger().

+ Here is the call graph for this function:

◆ getActiveAuthModes()

static ilAuthProviderLTI::getActiveAuthModes ( )
static

get all active authmode server ids

Returns
array

Definition at line 68 of file class.ilAuthProviderLTI.php.

68 : array
69 {
70 global $ilDB;
71
72 // move to connector
73 $query = 'SELECT consumer_pk from lti2_consumer where enabled = ' . $ilDB->quote(1, 'integer');
74 $res = $ilDB->query($query);
75
76 $sids = array();
77 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
78 $sids[] = $row->consumer_pk;
79 }
80 return $sids;
81 }

References $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilAuthUtils\_isExternalAccountEnabled().

+ Here is the caller graph for this function:

◆ getAuthModeByKey()

static ilAuthProviderLTI::getAuthModeByKey ( string  $a_auth_key)
static

Get auth mode by key.

Parameters
string$a_auth_mode
Returns
string auth_mode

Definition at line 41 of file class.ilAuthProviderLTI.php.

41 : string
42 {
43 $auth_arr = explode('_', $a_auth_key);
44 if (count($auth_arr) > 1) {
45 return 'lti_' . $auth_arr[1];
46 }
47 return 'lti';
48 }

Referenced by ilAuthUtils\_getAuthModeName().

+ Here is the caller graph for this function:

◆ getAuthModes()

static ilAuthProviderLTI::getAuthModes ( )
static
Returns
array

Definition at line 86 of file class.ilAuthProviderLTI.php.

86 : array
87 {
88 global $ilDB;
89
90 // move to connector
91 $query = 'SELECT distinct(consumer_pk) consumer_pk from lti2_consumer';
92 $res = $ilDB->query($query);
93
94 $sids = array();
95 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
96 $sids[] = $row->consumer_pk;
97 }
98 return $sids;
99 }

References $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilAuthUtils\_getActiveAuthModes(), and ilAuthUtils\_getAllAuthModes().

+ Here is the caller graph for this function:

◆ getKeyByAuthMode()

static ilAuthProviderLTI::getKeyByAuthMode ( string  $a_auth_mode)
static

Get auth id by auth mode.

Parameters
string$a_auth_mode
Returns
int|string auth_mode

Definition at line 55 of file class.ilAuthProviderLTI.php.

56 {
57 $auth_arr = explode('_', $a_auth_mode);
58 if (count($auth_arr) > 1) {
59 return ilAuthUtils::AUTH_PROVIDER_LTI . '_' . $auth_arr[1];
60 }
62 }

References ilAuthUtils\AUTH_PROVIDER_LTI.

Referenced by ilAuthUtils\_getAuthMode().

+ Here is the caller graph for this function:

◆ getServerIdByAuthMode()

static ilAuthProviderLTI::getServerIdByAuthMode ( string  $a_auth_mode)
static

Get auth id by auth mode.

Parameters
string$a_auth_mode
Returns
int|null

Definition at line 118 of file class.ilAuthProviderLTI.php.

118 : ?int
119 {
120 if (self::isAuthModeLTI($a_auth_mode)) {
121 $auth_arr = explode('_', $a_auth_mode);
122 return (int) $auth_arr[1];
123 }
124 return null;
125 }

Referenced by ilAuthUtils\getAuthModeTranslation().

+ Here is the caller graph for this function:

◆ handleLocalRoleAssignments()

ilAuthProviderLTI::handleLocalRoleAssignments ( int  $user_id,
ilLTIPlatform  $consumer 
)
protected

Definition at line 526 of file class.ilAuthProviderLTI.php.

526 : bool
527 {
528 global $DIC;
529 // if (empty($this->messageParameters)) {
530 // $status->setReason('empty_lti_message_parameters');
531 // $status->setStatus(ilAuthStatus::STATUS_AUTHENTICATION_FAILED);
532 // return false;
533 // }
534 //$target_ref_id = $_SESSION['lti_current_context_id'];
535 $target_ref_id = $this->ref_id;
536 $this->getLogger()->info('$target_ref_id: ' . $target_ref_id);
537 if (!$target_ref_id) {
538 $this->getLogger()->warning('No target id given');
539 return false;
540 }
541
542 $obj_settings = new ilLTIProviderObjectSetting($target_ref_id, $consumer->getExtConsumerId());
543
544 // @todo read from lti data
545 //$roles = $DIC->http()->wrapper()->post()->retrieve('roles', $DIC->refinery()->kindlyTo()->string());
546 $roles = $this->messageParameters['roles'];
547
548 if (!strlen($roles)) {
549 $this->getLogger()->warning('No role information given');
550 return false;
551 }
552 $role_arr = explode(',', $roles);
553 foreach ($role_arr as $role_name) {
554 $role_name = trim($role_name);
555 $role_name = str_replace('http://purl.imsglobal.org/vocab/lis/v2/membership#', '', $role_name);
556 switch ($role_name) {
557 case 'Administrator':
558 $this->getLogger()->info('Administrator role handling');
559 if ($obj_settings->getAdminRole()) {
560 $GLOBALS['DIC']->rbac()->admin()->assignUser(
561 $obj_settings->getAdminRole(),
563 );
564 }
565 break;
566
567 case 'Instructor':
568 case 'Mentor':
569 case 'TeachingAssistant':
570 $this->getLogger()->info('Instructor role handling');
571 $this->getLogger()->info('Tutor role for request: ' . $obj_settings->getTutorRole());
572 if ($obj_settings->getTutorRole()) {
573 $GLOBALS['DIC']->rbac()->admin()->assignUser(
574 $obj_settings->getTutorRole(),
576 );
577 }
578 break;
579
580 case 'Member':
581 case 'Learner':
582 $this->getLogger()->info('Member role handling');
583 if ($obj_settings->getMemberRole()) {
584 $GLOBALS['DIC']->rbac()->admin()->assignUser(
585 $obj_settings->getMemberRole(),
587 );
588 }
589 break;
590 default: // ToDo: correct parsing of lti1.3 roles
591 $this->getLogger()->info('default role handling');
592 if ($obj_settings->getMemberRole()) {
593 $GLOBALS['DIC']->rbac()->admin()->assignUser(
594 $obj_settings->getMemberRole(),
596 );
597 }
598 }
599 }
600 return true;
601 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $DIC, $GLOBALS, $ref_id, ilAuthProvider\$user_id, ilLTIPlatform\getExtConsumerId(), and ilAuthProvider\getLogger().

+ Here is the call graph for this function:

◆ isAuthModeLTI()

static ilAuthProviderLTI::isAuthModeLTI ( string  $a_auth_mode)
static

Check if user auth mode is LTI.

Parameters
string$a_auth_mode
Returns
bool

Definition at line 132 of file class.ilAuthProviderLTI.php.

132 : bool
133 {
134 if (!$a_auth_mode) {
135 ilLoggerFactory::getLogger('ltis')->warning('No auth mode given.');
136 return false;
137 }
138 $auth_arr = explode('_', $a_auth_mode);
139 return ($auth_arr[0] == ilAuthUtils::AUTH_PROVIDER_LTI) and $auth_arr[1];
140 }
static getLogger(string $a_component_id)
Get component logger.

References ilAuthUtils\AUTH_PROVIDER_LTI, and ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

◆ lookupConsumer()

static ilAuthProviderLTI::lookupConsumer ( int  $a_sid)
static

Lookup consumer title.

Parameters
int$a_sid
Returns
string

Definition at line 106 of file class.ilAuthProviderLTI.php.

106 : string
107 {
108 $connector = new ilLTIDataConnector();
109 $consumer = ilLTIPlatform::fromRecordId($a_sid, $connector);
110 return $consumer->getTitle();
111 }
static fromRecordId(int $id, ilLTIDataConnector $dataConnector)
Load the platform from the database by its record ID.

References ilLTIPlatform\fromRecordId().

Referenced by ilAuthUtils\getAuthModeTranslation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateUser()

ilAuthProviderLTI::updateUser ( int  $a_local_user_id,
ilLTIPlatform  $consumer 
)
protected

update existing user @access protected

Parameters
int$a_local_user_id
ilLTIPlatform$consumer
Returns
int

Definition at line 371 of file class.ilAuthProviderLTI.php.

371 : int
372 {
373 global $ilClientIniFile, $DIC;
374 // if (empty($this->messageParameters)) {
375 // $status->setReason('empty_lti_message_parameters');
376 // $status->setStatus(ilAuthStatus::STATUS_AUTHENTICATION_FAILED);
377 // return false;
378 // }
379 $user_obj = new ilObjUser($a_local_user_id);
380 if (isset($this->messageParameters['lis_person_name_given'])) {
381 $user_obj->setFirstname($this->messageParameters['lis_person_name_given']);
382 } else {
383 $user_obj->setFirstname('-');
384 }
385 if (isset($this->messageParameters['lis_person_name_family'])) {
386 $user_obj->setLastname($this->messageParameters['lis_person_name_family']);
387 } else {
388 $user_obj->setLastname('-');
389 }
390 $user_obj->setEmail($this->messageParameters['lis_person_contact_email_primary']);
391
392 $user_obj->setActive(true);
393
394 $until = $user_obj->getTimeLimitUntil();
395
396 if ($until < (time() + (int) $ilClientIniFile->readVariable('session', 'expire'))) {
397 $user_obj->setTimeLimitFrom(time() - 60);
398 $user_obj->setTimeLimitUntil(time() + (int) $ilClientIniFile->readVariable("session", "expire"));
399 }
400 $user_obj->update();
401 $user_obj->refreshLogin();
402
403 $GLOBALS['DIC']->rbac()->admin()->assignUser($consumer->getRole(), $user_obj->getId());
404 $this->getLogger()->debug('Assigned user to: ' . $consumer->getRole());
405
406 $this->getLogger()->info('Update of lti user with uid: ' . $user_obj->getId() . ' and login: ' . $user_obj->getLogin());
407 return $user_obj->getId();
408 }

References $DIC, $GLOBALS, ilAuthProvider\getLogger(), and ilLTIPlatform\getRole().

+ Here is the call graph for this function:

Field Documentation

◆ $dataConnector

ilLTIDataConnector ilAuthProviderLTI::$dataConnector = null
private

Definition at line 30 of file class.ilAuthProviderLTI.php.

◆ $lti_context_id

string ilAuthProviderLTI::$lti_context_id = ""
private

Definition at line 31 of file class.ilAuthProviderLTI.php.

◆ $messageParameters

array ilAuthProviderLTI::$messageParameters = null
private

Definition at line 34 of file class.ilAuthProviderLTI.php.

◆ $provider

ilLTITool ilAuthProviderLTI::$provider = null
private

Definition at line 33 of file class.ilAuthProviderLTI.php.

◆ $ref_id

int ilAuthProviderLTI::$ref_id = 0
private

Definition at line 32 of file class.ilAuthProviderLTI.php.

Referenced by handleLocalRoleAssignments().

◆ AUTH_MODE_PREFIX

const ilAuthProviderLTI::AUTH_MODE_PREFIX = 'lti'

Definition at line 29 of file class.ilAuthProviderLTI.php.


The documentation for this class was generated from the following file: