outcome_service.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. require_once './OAuthSimple.php';
  6. header('Content-Type: application/xml');
  7. if (empty($_GET['t'])) {
  8. exit;
  9. }
  10. $em = Database::getManager();
  11. /** @var ImsLtiTool $tool */
  12. $tool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', (int) $_GET['t']);
  13. if (empty($tool)) {
  14. exit;
  15. }
  16. $body = file_get_contents('php://input');
  17. $bodyHash = OAuthSimple::generateBodyHash($body);
  18. $url = api_get_path(WEB_PATH).'ims_lti/outcome_service/'.$tool->getId();
  19. $headers = getallheaders();
  20. $params = OAuthSimple::getAuthorizationParams($headers['Authorization']);
  21. if (empty($params)) {
  22. exit;
  23. }
  24. $oauth = new OAuthSimple(
  25. $params['oauth_consumer_key'],
  26. $tool->getSharedSecret()
  27. );
  28. $oauth->setAction('POST');
  29. $oauth->setSignatureMethod('HMAC-SHA1');
  30. $result = $oauth->sign(
  31. [
  32. 'path' => $url,
  33. 'parameters' => [
  34. 'oauth_body_hash' => $params['oauth_body_hash'],
  35. 'oauth_nonce' => $params['oauth_nonce'],
  36. 'oauth_timestamp' => $params['oauth_timestamp'],
  37. 'oauth_signature_method' => $params['oauth_signature_method'],
  38. ],
  39. ]
  40. );
  41. $signatureValid = urldecode($result['signature']) == $params['oauth_signature'];
  42. $bodyHashValid = $bodyHash === $params['oauth_body_hash'];
  43. if (!$signatureValid || !$bodyHashValid) {
  44. exit;
  45. }
  46. $plugin = ImsLtiPlugin::create();
  47. $process = $plugin->processServiceRequest();
  48. echo $process;