5use IMSGlobal\LTI\ToolProvider;
 
    7include_once 
'./Services/Authentication/classes/Provider/class.ilAuthProvider.php';
 
    8include_once 
'./Services/Authentication/interfaces/interface.ilAuthProviderInterface.php';
 
    9include_once 
'./Services/LTI/classes/InternalProvider/class.ilLTIToolProvider.php';
 
   10require_once 
'Services/LTI/classes/class.ilLTIDataConnector.php';
 
   32        if (isset(
$_POST[
'launch_presentation_document_target']) && 
$_POST[
'launch_presentation_document_target'] == 
'blank') {
 
   33            $_POST[
'launch_presentation_document_target'] = 
'window';
 
   40        $ok = $lti_provider->handleRequest();
 
   43            $this->
getLogger()->info(
'LTI authentication failed with message: ' . $lti_provider->reason);
 
   44            $status->setReason($lti_provider->reason);
 
   48            $this->
getLogger()->debug(
'LTI authentication success');
 
   59            $consumer->getRecordId(),
 
   63        $this->ref_id = $consumer->getRefId();
 
   65        $lti_context_ids = 
$_SESSION[
'lti_context_ids'];
 
   67        if (isset($lti_context_ids) && is_array($lti_context_ids)) {
 
   68            if (!in_array($this->ref_id, $lti_context_ids)) {
 
   69                $this->
getLogger()->debug(
"push new lti ref_id: " . $this->ref_id);
 
   70                array_push($lti_context_ids,$this->ref_id);
 
   71                $_SESSION[
'lti_context_ids'] = $lti_context_ids;
 
   76            $this->
getLogger()->debug(
"lti_context_ids is not set. Create new array...");
 
   77            $_SESSION[
'lti_context_ids'] = array($this->ref_id);
 
   90        if (!$consumer->enabled) {
 
   91            $this->
getLogger()->warning(
'Consumer is not enabled');
 
   92            $status->
setReason(
'lti_consumer_inactive');
 
   97        if (!$consumer->getActive()) {
 
   98            $this->
getLogger()->warning(
'Consumer is not active');
 
   99            $status->
setReason(
'lti_consumer_inactive');
 
  104        $lti_id = $consumer->getExtConsumerId();
 
  106            $status->setReason(
'lti_auth_failed_invalid_key');
 
  111        $this->
getLogger()->debug(
'Using prefix:' . $consumer->getPrefix());
 
  115        if ($internal_account) {
 
  116            $this->
updateUser($internal_account, $consumer);
 
  118            $internal_account = $this->
createUser($consumer);
 
  124        $status->setAuthenticatedUserId($internal_account);
 
  140        $query = 
'SELECT consumer_pk from lti2_consumer where consumer_key256 = ' . 
$ilDB->quote($a_oauth_consumer_key, 
'text');
 
  147            $lti_id = $row->consumer_pk;
 
  150        $this->
getLogger()->debug(
'External consumer key is: ' . (
int) $lti_id);
 
  162        $query = 
'SELECT prefix from lti_ext_consumer where id = ' . 
$ilDB->quote($a_lti_id, 
'integer');
 
  169            $prefix = $row->prefix;
 
  171        $this->
getLogger()->debug(
'LTI prefix: ' . $prefix);
 
  182        $query = 
'SELECT role from lti_ext_consumer where id = ' . 
$ilDB->quote($a_lti_id, 
'integer');
 
  190        $this->
getLogger()->debug(
'LTI role: ' . $role);
 
  199    protected function findUserId($a_oauth_user, $a_oauth_id, $a_user_prefix)
 
  202            self::AUTH_MODE_PREFIX . 
'_' . $a_oauth_id,
 
  209        $this->
getLogger()->debug(
'Found user with auth mode lti_' . $a_oauth_id . 
' with user_id: ' . 
$user_id);
 
  224        include_once(
'./Services/Authentication/classes/class.ilAuthUtils.php');
 
  227        $newUser[
"login"] = $local_user;
 
  228        $newUser[
"firstname"] = 
$_POST[
'lis_person_name_given'];
 
  229        $newUser[
"lastname"] = 
$_POST[
'lis_person_name_family'];
 
  230        $newUser[
'email'] = 
$_POST[
'lis_person_contact_email_primary'];
 
  234        $newUser[
"passwd"] = 
"";
 
  239        $newUser[
"profile_incomplete"] = 0;
 
  242        $userObj->assignData($newUser);
 
  243        $userObj->setTitle($userObj->getFullname());
 
  244        $userObj->setDescription($userObj->getEmail());
 
  250        $userObj->setTimeLimitOwner(7);
 
  251        $userObj->setTimeLimitUnlimited(0);
 
  252        $userObj->setTimeLimitFrom(time() - 5);
 
  253        $userObj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable(
"session", 
"expire"));
 
  257        $userObj->setOwner(6);
 
  259        $userObj->setActive(1);
 
  260        $userObj->updateOwner();
 
  261        $userObj->saveAsNew();
 
  262        $userObj->writePrefs();
 
  264        $GLOBALS[
'DIC']->rbac()->admin()->assignUser($consumer->
getRole(), $userObj->getId());
 
  266        $this->
getLogger()->info(
'Created new lti user with uid: ' . $userObj->getId() . 
' and login: ' . $userObj->getLogin());
 
  267        return $userObj->getId();
 
  277        global $ilClientIniFile,
$ilLog,$rbacadmin;
 
  279        $user_obj = 
new ilObjUser($a_local_user_id);
 
  280        $user_obj->setFirstname(
$_POST[
'lis_person_name_given']);
 
  281        $user_obj->setLastname(
$_POST[
'lis_person_name_family']);
 
  282        $user_obj->setEmail(
$_POST[
'lis_person_contact_email_primary']);
 
  283        $user_obj->setActive(
true);
 
  285        $until = $user_obj->getTimeLimitUntil();
 
  287        if ($until < (time() + $ilClientIniFile->readVariable(
'session', 
'expire'))) {
 
  288            $user_obj->setTimeLimitFrom(time() - 60);
 
  289            $user_obj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable(
"session", 
"expire"));
 
  292        $user_obj->refreshLogin();
 
  294        $GLOBALS[
'DIC']->rbac()->admin()->assignUser($consumer->
getRole(), $user_obj->getId());
 
  297        $this->
getLogger()->info(
'Update of lti user with uid: ' . $user_obj->getId() . 
' and login: ' . $user_obj->getLogin());
 
  298        return $user_obj->getId();
 
  304        $target_ref_id = $this->ref_id;
 
  305        $this->
getLogger()->info(
'$target_ref_id: ' . $target_ref_id);
 
  306        if (!$target_ref_id) {
 
  307            $this->
getLogger()->warning(
'No target id given');
 
  315        if (!strlen($roles)) {
 
  316            $this->
getLogger()->warning(
'No role information given');
 
  319        $role_arr = explode(
',', $roles);
 
  320        foreach ($role_arr as $role_name) {
 
  321            $role_name = trim($role_name);
 
  322            switch ($role_name) {
 
  323                case 'Administrator':
 
  324                    $this->
getLogger()->info(
'Administrator role handling');
 
  325                    if ($obj_settings->getAdminRole()) {
 
  326                        $GLOBALS[
'DIC']->rbac()->admin()->assignUser(
 
  327                            $obj_settings->getAdminRole(),
 
  334                    $this->
getLogger()->info(
'Instructor role handling');
 
  335                    $this->
getLogger()->info(
'Tutor role for request: ' . $obj_settings->getTutorRole());
 
  336                    if ($obj_settings->getTutorRole()) {
 
  337                        $GLOBALS[
'DIC']->rbac()->admin()->assignUser(
 
  338                            $obj_settings->getTutorRole(),
 
  346                    $this->
getLogger()->info(
'Member role handling');
 
  347                    if ($obj_settings->getMemberRole()) {
 
  348                        $GLOBALS[
'DIC']->rbac()->admin()->assignUser(
 
  349                            $obj_settings->getMemberRole(),
 
  365        $auth_arr = explode(
'_', $a_auth_key);
 
  366        if (count((array) $auth_arr) > 1) {
 
  367            return 'lti_' . $auth_arr[1];
 
  379        $auth_arr = explode(
'_', $a_auth_mode);
 
  380        if (count((array) $auth_arr) > 1) {
 
  395        $query = 
'SELECT consumer_pk from lti2_consumer where enabled = ' . 
$ilDB->quote(1, 
'integer');
 
  400            $sids[] = $row->consumer_pk;
 
  410        $query = 
'SELECT distinct(consumer_pk) consumer_pk from lti2_consumer';
 
  415            $sids[] = $row->consumer_pk;
 
  427        include_once 
'./Services/LTI/classes/class.ilLTIDataConnector.php';
 
  429        include_once 
'./Services/LTI/classes/InternalProvider/class.ilLTIToolConsumer.php';
 
  431        return $consumer->getTitle();
 
  441        if (self::isAuthModeLTI($a_auth_mode)) {
 
  442            $auth_arr = explode(
'_', $a_auth_mode);
 
  458        $auth_arr = explode(
'_', $a_auth_mode);
 
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
An exception for terminatinating execution or to throw for unit testing.
OAuth based lti authentication.
static getActiveAuthModes()
get all active authmode server ids
static getKeyByAuthMode($a_auth_mode)
Get auth id by auth mode.
updateUser($a_local_user_id, ilLTIToolConsumer $consumer)
update existing user
findGlobalRole($a_lti_id)
find global role of consumer
static lookupConsumer($a_sid)
Lookup consumer title.
findUserId($a_oauth_user, $a_oauth_id, $a_user_prefix)
Find user by auth mode and lti id.
findAuthKeyId($a_oauth_consumer_key)
find consumer key id @global type $ilDB
findAuthPrefix($a_lti_id)
find lti id
createUser(ilLTIToolConsumer $consumer)
create new user
handleLocalRoleAssignments($user_id, ilLTIToolConsumer $consumer)
static getServerIdByAuthMode($a_auth_mode)
Get auth id by auth mode.
static isAuthModeLTI($a_auth_mode)
Check if user auth mode is LTI.
static getAuthModeByKey($a_auth_key)
Get auth mode by key.
Base class for authentication providers (radius, ldap, apache, ...)
Auth status implementation.
const STATUS_AUTHENTICATED
setReason($a_reason)
Set reason.
const STATUS_AUTHENTICATION_FAILED
static _generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
Class to represent an LTI Data Connector for ILIAS.
static getLogger($a_component_id)
Get component logger.
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
static _lookupId($a_user_str)
Lookup id by login.
static _lookupType($a_id, $a_reference=false)
lookup object type
Standard interface for auth provider implementations.
doAuthentication(\ilAuthStatus $status)
Do authentication.
foreach($_POST as $key=> $value) $res