ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilLTIConsumerLaunch.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 use ILIAS\LTIOAuth;
22 
32 {
33  private ?array $context = null;
34  protected int $ref_id;
35 
39  public function __construct(int $a_ref_id)
40  {
41  $this->ref_id = $a_ref_id;
42  }
43 
52  public function getContext(?array $a_valid_types = array('crs', 'grp', 'cat', 'root')): ?array
53  {
54  global $DIC; /* @var \ILIAS\DI\Container $DIC */
55  $tree = $DIC->repositoryTree();
56 
57  if (!isset($this->context)) {
58  $this->context = array();
59 
60  // check fromm inner to outer
61  $path = array_reverse($tree->getPathFull($this->ref_id));
62  foreach ($path as $row) {
63  if (in_array($row['type'], $a_valid_types)) {
64  // take an existing inner context outside a course
65  if (in_array($row['type'], array('cat', 'root')) && !empty($this->context)) {
66  break;
67  }
68 
69  $this->context['id'] = (string) $row['child'];
70  $this->context['title'] = $row['title'];
71  $this->context['type'] = $row['type'];
72 
73  // don't break to get the most outer course or group
74  }
75  }
76  }
77  return $this->context;
78  }
79 
80 
81 
82 
83  public static function getLTIContextType(string $a_type): string
84  {
85  switch ($a_type) {
86  case "crs":
87  return "CourseOffering";
88  case "grp":
89  return "Group";
90  case "root":
91  return "urn:lti:context-type:ilias/RootNode";
92  case "cat":
93  default:
94  return "urn:lti:context-type:ilias/Category";
95  }
96  }
97 
98 
99 
113  public static function signOAuth(array $a_params)
114  {
115  switch ($a_params['sign_method']) {
116  case "HMAC_SHA1":
117  $method = new ILIAS\LTIOAuth\OAuthSignatureMethod_HMAC_SHA1();
118  break;
119  case "PLAINTEXT":
120  $method = new ILIAS\LTIOAuth\OAuthSignatureMethod_PLAINTEXT();
121  break;
122  // case "RSA_SHA1":
123  // $method = new ILIAS\LTIOAuth\OAuthSignatureMethod_RSA_SHA1();
124  // break;
125 
126  default:
127  return "ERROR: unsupported signature method!";
128  }
129  $consumer = new ILIAS\LTIOAuth\OAuthConsumer($a_params["key"], $a_params["secret"], $a_params["callback"]);
130  $request = ILIAS\LTIOAuth\OAuthRequest::from_consumer_and_token($consumer, $a_params["token"], $a_params["http_method"], $a_params["url"], $a_params["data"]);
131  $request->sign_request($method, $consumer, $a_params["token"]);
132 
133  // Pass this back up "out of band" for debugging
134  // self::$last_oauth_base_string = $request->get_signature_base_string();
135  // die(self::$last_oauth_base_string);
136 
137  return $request->get_parameters();
138  }
139 }
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 ...
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
__construct(int $a_ref_id)
ilObjLTIConsumerLaunch constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: OAuth.php:21
static getLTIContextType(string $a_type)
static signOAuth(array $a_params)
sign request data with OAuth