ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLTIConsumerLaunch.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ceLTIc\LTI\OAuth\OAuthConsumer;
22use ceLTIc\LTI\OAuth\OAuthRequest;
23use ceLTIc\LTI\OAuth\OAuthSignatureMethod_HMAC_SHA1;
24
34{
35 private ?array $context = null;
36 protected int $ref_id;
37
41 public function __construct(int $a_ref_id)
42 {
43 $this->ref_id = $a_ref_id;
44 }
45
54 public function getContext(?array $a_valid_types = array('crs', 'grp', 'cat', 'root')): ?array
55 {
56 global $DIC; /* @var \ILIAS\DI\Container $DIC */
57 $tree = $DIC->repositoryTree();
58
59 if (!isset($this->context)) {
60 $this->context = array();
61
62 // check fromm inner to outer
63 $path = array_reverse($tree->getPathFull($this->ref_id));
64 foreach ($path as $row) {
65 if (in_array($row['type'], $a_valid_types)) {
66 // take an existing inner context outside a course
67 if (in_array($row['type'], array('cat', 'root')) && !empty($this->context)) {
68 break;
69 }
70
71 $this->context['id'] = $row['child'];
72 $this->context['title'] = $row['title'];
73 $this->context['type'] = $row['type'];
74
75 // don't break to get the most outer course or group
76 }
77 }
78 }
79 return $this->context;
80 }
81
82
83
84
85 public static function getLTIContextType(string $a_type): string
86 {
87 switch ($a_type) {
88 case "crs":
89 return "http://purl.imsglobal.org/vocab/lis/v2/course#CourseOffering";
90 case "grp":
91 return "http://purl.imsglobal.org/vocab/lis/v2/course#Group";
92 case "root":
93 return "http://purl.imsglobal.org/vocab/lis/v2/course#CourseOffering";
94 case "cat":
95 default:
96 return "http://purl.imsglobal.org/vocab/lis/v2/course#CourseOffering";
97 }
98 }
99
100
115 public static function signOAuth(array $a_params): array
116 {
117 switch ($a_params['sign_method']) {
118 case "HMAC_SHA1":
119 $method = new OAuthSignatureMethod_HMAC_SHA1();
120 break;
121 default:
122 throw new Exception("Unknown signature method: " . $a_params['sign_method']);
123 }
124
125 $consumer = new OAuthConsumer($a_params["key"], $a_params["secret"], $a_params["callback"]);
126 $request = OAuthRequest::from_consumer_and_token($consumer, $a_params["token"], $a_params["http_method"], $a_params["url"], $a_params["data"]);
127 $request->sign_request($method, $consumer, $a_params["token"]);
128
129 // Pass this back up "out of band" for debugging
130 // self::$last_oauth_base_string = $request->get_signature_base_string();
131 // die(self::$last_oauth_base_string);
132
133 return $request->get_parameters();
134 }
135}
static getLTIContextType(string $a_type)
static signOAuth(array $a_params)
sign request data with OAuth
getContext(?array $a_valid_types=array('crs', 'grp', 'cat', 'root'))
get info about the context in which the link is used The most outer matching course or group is used ...
__construct(int $a_ref_id)
ilObjLTIConsumerLaunch constructor.
$path
Definition: ltiservices.php:30
global $DIC
Definition: shib_login.php:26