ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLTIConsumerLaunch.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
15 {
16  private static $last_oauth_base_string = "";
17  // protected $context = null;
18  protected $ref_id;
19 
25  public function __construct(int $a_ref_id)
26  {
27  $this->ref_id = $a_ref_id;
28  }
29 
39  public function getContext($a_valid_types = array('crs', 'grp', 'cat', 'root'))
40  {
41  global $DIC; /* @var \ILIAS\DI\Container $DIC */
42  $tree = $DIC->repositoryTree();
43 
44  if (!isset($this->context)) {
45  $this->context = array();
46 
47  // check fromm inner to outer
48  $path = array_reverse($tree->getPathFull($this->ref_id));
49  foreach ($path as $key => $row) {
50  if (in_array($row['type'], $a_valid_types)) {
51  // take an existing inner context outside a course
52  if (in_array($row['type'], array('cat', 'root')) && !empty($this->context)) {
53  break;
54  }
55 
56  $this->context['id'] = $row['child'];
57  $this->context['title'] = $row['title'];
58  $this->context['type'] = $row['type'];
59 
60  // don't break to get the most outer course or group
61  }
62  }
63  }
64  return $this->context;
65  }
66 
67 
68 
69 
70  public static function getLTIContextType($a_type)
71  {
72  switch ($a_type) {
73  case "crs":
74  return "CourseOffering";
75  break;
76  case "grp":
77  return "Group";
78  break;
79  case "root":
80  return "urn:lti:context-type:ilias/RootNode";
81  break;
82  case "cat":
83  default:
84  return "urn:lti:context-type:ilias/Category";
85  break;
86  }
87  }
88 
89 
90 
104  public static function signOAuth($a_params)
105  {
106  require_once('./Modules/LTIConsumer/lib/OAuth.php');
107  switch ($a_params['sign_method']) {
108  case "HMAC_SHA1":
109  $method = new OAuthSignatureMethod_HMAC_SHA1();
110  break;
111  case "PLAINTEXT":
112  $method = new OAuthSignatureMethod_PLAINTEXT();
113  break;
114  case "RSA_SHA1":
115  $method = new OAuthSignatureMethod_RSA_SHA1();
116  break;
117 
118  default:
119  return "ERROR: unsupported signature method!";
120  }
121 
122  $consumer = new OAuthConsumer($a_params["key"], $a_params["secret"], $a_params["callback"]);
123  $request = OAuthRequest::from_consumer_and_token($consumer, $a_params["token"], $a_params["http_method"], $a_params["url"], $a_params["data"]);
124  $request->sign_request($method, $consumer, $a_params["token"]);
125 
126  // Pass this back up "out of band" for debugging
127  self::$last_oauth_base_string = $request->get_signature_base_string();
128  // die(self::$last_oauth_base_string);
129 
130  return $request->get_parameters();
131  }
132 }
$context
Definition: webdav.php:26
__construct(int $a_ref_id)
ilObjLTIConsumerLaunch constructor.
static signOAuth($a_params)
sign request data with OAuth
global $DIC
Definition: goto.php:24
static from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=null)
pretty much a helper function to set up the request
Definition: OAuth.php:284
getContext($a_valid_types=array('crs', 'grp', 'cat', 'root'))
get info about the context in which the link is used