ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ltiauth.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22require_once("../vendor/composer/vendor/autoload.php");
23
24
29if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
30 $orig = new ArrayObject($_POST);
31 $data = $orig->getArrayCopy();
32} elseif (strtoupper($_SERVER['REQUEST_METHOD']) == 'GET') {
33 $orig = new ArrayObject($_GET);
34 $data = $orig->getArrayCopy();
35 // early removing client_id from $_GET
36 // otherwise the client_id is interpreted as ILIAS client_id
37 // and client.ini.php will not be found
38 if (isset($_GET['client_id'])) {
39 unset($_GET['client_id']);
40 }
41} else {
42 header($_SERVER["SERVER_PROTOCOL"] . " 405 Method Not Allowed", true, 405);
44}
45
47
48global $DIC;
49
50$ltiMessageHint = $data['lti_message_hint'];
51
52if (empty($ltiMessageHint)) {
53 $DIC->http()->saveResponse(
54 $DIC->http()->response()
55 ->withStatus(400)
56 );
57 try {
58 $DIC->http()->sendResponse();
59 $DIC->http()->close();
60 } catch (\ILIAS\HTTP\Response\Sender\ResponseSendingException $e) {
61 $DIC->http()->close();
62 }
63}
64$mh = explode(":", $ltiMessageHint);
69if (count($mh) == 2) { // launch message auth
70 list($ref_id, $client_id) = explode(":", $ltiMessageHint);
71} else { // contentSelection message auth
73 list($ref_id, $client_id, $redirect_uri) = explode(":", $ltiMessageHint);
74}
75
76ilSession::set('lti13_login_data', $data);
78 $url = "../../../" . base64_decode($redirect_uri);
79} else {
80 $url = "../../../goto.php?target=lti_" . $ref_id . "&client_id=" . $client_id;
81}
82
84{
85 if (session_status() !== PHP_SESSION_ACTIVE || session_id() === '') {
86 return null;
87 }
88
89 $cookieParams = session_get_cookie_params();
90 $secure = (bool) ($cookieParams['secure'] ?? false);
91 if (!$secure) {
92 return null;
93 }
94
95 $cookieName = session_name();
96 $cookieValue = session_id();
97 $path = (string) ($cookieParams['path'] ?? '/');
98 $domain = (string) ($cookieParams['domain'] ?? '');
99 $httpOnly = (bool) ($cookieParams['httponly'] ?? true);
100
101 $parts = [
102 rawurlencode($cookieName) . '=' . rawurlencode($cookieValue),
103 'Path=' . $path,
104 'Secure',
105 'SameSite=None'
106 ];
107
108 if ($domain !== '') {
109 $parts[] = 'Domain=' . $domain;
110 }
111 if ($httpOnly) {
112 $parts[] = 'HttpOnly';
113 }
114
115 return implode('; ', $parts);
116}
117
118$response = $DIC->http()->response()
119 ->withStatus(302)
120 ->withAddedHeader('Location', $url);
121
123if ($sessionCookieHeader !== null) {
124 $response = $response->withAddedHeader('Set-Cookie', $sessionCookieHeader);
125}
126
127$DIC->http()->saveResponse(
129);
130try {
131 $DIC->http()->sendResponse();
132 $DIC->http()->close();
133} catch (\ILIAS\HTTP\Response\Sender\ResponseSendingException $e) {
134 $DIC->http()->close();
135}
static initILIAS()
ilias initialisation
static set(string $a_var, $a_val)
Set a value.
$_GET['cmd']
Definition: lti.php:26
$_POST['cmd']
Definition: lti.php:27
$redirect_uri
Definition: ltiauth.php:68
$client_id
Definition: ltiauth.php:67
$sessionCookieHeader
Definition: ltiauth.php:122
$isContentSelection
Definition: ltiauth.php:65
global $DIC
Definition: ltiauth.php:48
exit
Definition: ltiauth.php:43
if(empty($ltiMessageHint)) $mh
Definition: ltiauth.php:64
$ltiMessageHint
Definition: ltiauth.php:50
buildSameSiteNoneSessionCookieHeader()
Definition: ltiauth.php:83
$ref_id
Definition: ltiauth.php:66
$response
Definition: ltiauth.php:118
$path
Definition: ltiservices.php:30
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$url
Definition: shib_logout.php:70