outcome_service.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
  4. require_once __DIR__.'/../../main/inc/global.inc.php';
  5. header('Content-Type: application/xml');
  6. $url = api_get_path(WEB_PATH).'lti/os';
  7. $em = Database::getManager();
  8. $toolRepo = $em->getRepository('ChamiloPluginBundle:ImsLti\ImsLtiTool');
  9. $headers = OAuthUtil::get_headers();
  10. if (empty($headers['Authorization'])) {
  11. error_log('Authorization header missed');
  12. exit;
  13. }
  14. $authParams = OAuthUtil::split_header($headers['Authorization']);
  15. if (empty($authParams) || empty($authParams['oauth_consumer_key']) || empty($authParams['oauth_signature'])) {
  16. error_log('Authorization params not found');
  17. exit;
  18. }
  19. $tools = $toolRepo->findBy(['consumerKey' => $authParams['oauth_consumer_key']]);
  20. $toolIsFound = false;
  21. /** @var ImsLtiTool $tool */
  22. foreach ($tools as $tool) {
  23. $consumer = new OAuthConsumer($tool->getConsumerKey(), $tool->getSharedSecret());
  24. $hmacMethod = new OAuthSignatureMethod_HMAC_SHA1();
  25. $request = OAuthRequest::from_request('POST', $url);
  26. $request->sign_request($hmacMethod, $consumer, '');
  27. $signature = $request->get_parameter('oauth_signature');
  28. if ($signature === $authParams['oauth_signature']) {
  29. $toolIsFound = true;
  30. break;
  31. }
  32. }
  33. if (false === $toolIsFound) {
  34. error_log('Tool not found. Signature is not valid');
  35. exit;
  36. }
  37. $body = file_get_contents('php://input');
  38. $bodyHash = base64_encode(sha1($body, true));
  39. if ($bodyHash !== $authParams['oauth_body_hash']) {
  40. error_log('Authorization request not valid');
  41. exit;
  42. }
  43. $plugin = ImsLtiPlugin::create();
  44. $process = $plugin->processServiceRequest();
  45. echo $process;