/**
  * @param type $deliveryResultIdentifier lis_result_sourcedid
  * @param type $test ignored
  * @param taoResultServer_models_classes_Variable $testVariable
  * @param type $callIdTest ignored
  */
 public function storeTestVariable($deliveryResultIdentifier, $test, taoResultServer_models_classes_Variable $testVariable, $callIdTest)
 {
     if (get_class($testVariable) == "taoResultServer_models_classes_OutcomeVariable") {
         common_Logger::i("Outcome submission VariableId. (" . $testVariable->getIdentifier() . ") Result Identifier (" . $deliveryResultIdentifier . ")Service URL (" . $this->serviceUrl . ")");
         $variableIdentifier = $testVariable->getIdentifier();
         if ($variableIdentifier == LTI_OUTCOME_VARIABLE_IDENTIFIER) {
             $grade = (string) $testVariable->getValue();
             $message = taoLtiBasicOutcome_helpers_LtiBasicOutcome::buildXMLMessage($deliveryResultIdentifier, $grade, 'replaceResultRequest');
             //common_Logger::i("Preparing POX message for the outcome service :".$message."\n");
             $credentialResource = taoLti_models_classes_LtiService::singleton()->getCredential($this->consumerKey);
             //common_Logger::i("Credential for the consumerKey :". $credentialResource->getUri()."\n");
             $credentials = new tao_models_classes_oauth_Credentials($credentialResource);
             //$this->serviceUrl = "http://tao-dev/log.php";
             //Building POX raw http message
             $unSignedOutComeRequest = new common_http_Request($this->serviceUrl, 'POST', array());
             $unSignedOutComeRequest->setBody($message);
             $signingService = new tao_models_classes_oauth_Service();
             $signedRequest = $signingService->sign($unSignedOutComeRequest, $credentials, true);
             common_Logger::i("Request sent (Body)\n" . $signedRequest->getBody() . "\n");
             common_Logger::i("Request sent (Headers)\n" . serialize($signedRequest->getHeaders()) . "\n");
             common_Logger::i("Request sent (Headers)\n" . serialize($signedRequest->getParams()) . "\n");
             //Hack for moodle comaptibility, the header is ignored for the signature computation
             $signedRequest->setHeader("Content-Type", "application/xml");
             $response = $signedRequest->send();
             common_Logger::i("\nHTTP Code received: " . $response->httpCode . "\n");
             common_Logger::i("\nHTTP From: " . $response->effectiveUrl . "\n");
             common_Logger::i("\nHTTP Content received: " . $response->responseData . "\n");
             if ($response->httpCode != "200") {
                 throw new common_exception_Error("An HTTP level proble occured when sending the outcome to the service url");
             }
         }
     }
 }
예제 #2
0
 public function testSignature()
 {
     $request = new common_http_Request('http://example.com/oauthtest');
     $service = new tao_models_classes_oauth_Service();
     $signed = $service->sign($request, $this->oauthCustomer);
     //assert no exception
     $service->validate($signed);
 }
 /**
  * (non-PHPdoc)
  * @see common_user_auth_Adapter::authenticate()
  */
 public function authenticate()
 {
     $service = new tao_models_classes_oauth_Service();
     try {
         $service->validate($this->request);
         $ltiLaunchData = taoLti_models_classes_LtiLaunchData::fromRequest($this->request);
         return new taoLti_models_classes_LtiUser($ltiLaunchData);
     } catch (common_http_InvalidSignatureException $e) {
         throw new taoLti_models_classes_LtiException('Invalid LTI signature');
     }
 }
 /**
  * Launches a oauth tool
  */
 public function call()
 {
     if (!$this->hasRequestParameter('ltiConsumerUri')) {
         throw new common_exception_MissingParameter('ltiConsumerUri', get_class($this));
     }
     if (!$this->hasRequestParameter('ltiLaunchUrl')) {
         throw new common_exception_MissingParameter('ltiLaunchUrl', get_class($this));
     }
     $ltiConsumer = new tao_models_classes_oauth_Credentials($this->getRequestParameter('ltiConsumerUri'));
     $launchUrl = $this->getRequestParameter('ltiLaunchUrl');
     $serviceCallId = $this->getServiceCallId() . '_c';
     $session = common_session_SessionManager::getSession();
     $roles = array();
     foreach ($session->getUserRoles() as $role) {
         foreach (taoLti_models_classes_LtiUtils::mapTaoRole2LTIRoles($role) as $ltiRole) {
             $roles[] = $ltiRole;
         }
     }
     $ltiData = array('lti_message_type' => 'basic-lti-launch-request', 'lti_version' => 'LTI-1p0', 'resource_link_id' => rand(0, 9999999), 'resource_link_title' => 'Launch Title', 'resource_link_label' => 'Launch label', 'context_id' => $serviceCallId, 'context_title' => 'Launch Title', 'context_label' => 'Launch label', 'user_id' => $session->getUserUri(), 'roles' => implode(',', $roles), 'lis_person_name_full' => $session->getUserLabel(), 'tool_consumer_info_product_family_code' => PRODUCT_NAME, 'tool_consumer_info_version' => TAO_VERSION);
     // @todo add:
     /*
     user_id:
     roles:
     
     lis_person_name_full:
     lis_person_name_family:
     lis_person_name_given:
     lis_person_contact_email_primary:
     lis_person_sourcedid:
     
     tool_consumer_info_product_family_code:
     tool_consumer_info_version:
     tool_consumer_instance_guid:
     tool_consumer_instance_description:
     */
     $request = new common_http_Request($launchUrl, common_http_Request::METHOD_POST, $ltiData);
     $service = new tao_models_classes_oauth_Service();
     $signedRequest = $service->sign($request, $ltiConsumer);
     $this->setData('launchUrl', $launchUrl);
     $this->setData('ltiData', $signedRequest->getParams());
     $this->setData('client_config_url', $this->getClientConfigUrl());
     $this->setView('ltiConsumer.tpl');
 }