ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilLTILoginGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 public const string CMD_AUTHENTICATE = 'doLTIAuthentication';
30
31 private readonly ilCtrlInterface $ctrl;
33 private readonly ilAuthSession $auth_session;
34 private readonly ilLanguage $lng;
35 private readonly ilLogger $logger;
36
37 public function __construct()
38 {
39 global $DIC;
40
41 $this->ctrl = $DIC->ctrl();
42 $this->main_tpl = $DIC->ui()->mainTemplate();
43 $this->auth_session = $DIC['ilAuthSession'];
44 $this->lng = $DIC->language();
45 $this->logger = $DIC->logger()->forComponent('lti');
46 }
47
48 public function getUnsafeGetCommands(): array
49 {
50 return [];
51 }
52
56 public function getSafePostCommands(): array
57 {
59 }
60
61 public function executeCommand(): void
62 {
63 if ($this->ctrl->getCmd() === self::CMD_AUTHENTICATE) {
64 $this->authenticate();
65 }
66
67 $this->ctrl->redirectByClass(ilStartUpGUI::class, 'showLoginPage');
68 }
69
70 private function authenticate(): void
71 {
72 $this->logger->debug('Trying lti authentication');
73
74 $credentials = new ilAuthFrontendCredentialsLTI();
75 $credentials->initFromRequest();
76
77 $provider_factory = new ilAuthProviderFactory();
78 $provider = $provider_factory->getProviderByAuthMode($credentials, ilAuthUtils::AUTH_PROVIDER_LTI);
79
80 $status = ilAuthStatus::getInstance();
81
82 $frontend_factory = new ilAuthFrontendFactory();
83 $frontend_factory->setContext(ilAuthFrontendFactory::CONTEXT_STANDARD_FORM);
84 $frontend = $frontend_factory->getFrontend(
85 $this->auth_session,
86 $status,
87 $credentials,
88 [$provider]
89 );
90 $frontend->authenticate();
91
92 $lti_target = ilLTIViewGUI::getLaunchTarget();
93 if ($lti_target !== '') {
94 ilSession::set('orig_request_target', $lti_target);
95 }
96
97 switch ($status->getStatus()) {
100 // the user of a launch goes to the object the platform launched
101 if ($lti_target !== '') {
102 $this->ctrl->redirectToURL($lti_target);
103 }
104 $this->logger->debug('Authentication successful; Redirecting to starting page.');
106
107 // no break
109 $this->ctrl->redirectByClass(ilStartUpGUI::class, 'showAccountMigration');
110
111 // no break
113 $this->main_tpl->setOnScreenMessage('failure', $status->getTranslatedReason(), true);
114 $this->ctrl->redirectByClass(ilStartUpGUI::class, 'showLoginPage');
115 }
116
117 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('err_wrong_login'), true);
118 }
119}
The credentials of a launch: the id the platform gives the user.
const int CONTEXT_STANDARD_FORM
Authentication with id and password.
const int STATUS_AUTHENTICATION_FAILED
const int STATUS_ACCOUNT_MIGRATION_REQUIRED
const int STATUS_AUTHENTICATED
static getInstance()
Get status instance.
const int AUTH_PROVIDER_LTI
static redirectToStartingPage(string $target='')
Logs the user of a launch in, see lti.php.
getSafePostCommands()
A platform cannot send the token of ilCtrl.
readonly ilAuthSession $auth_session
readonly ilLogger $logger
readonly ilCtrlInterface $ctrl
readonly ilLanguage $lng
const string CMD_AUTHENTICATE
readonly ilGlobalTemplateInterface $main_tpl
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
static allowCrossSite()
Sends the session cookie again as SameSite=None, with the path and the domain of the one PHP sends so...
static getLaunchTarget()
The address the user of an accepted launch goes on to: the object the platform launched,...
language handling
Component logger with individual log levels by component id.
static set(string $a_var, $a_val)
Set a value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26