Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| LtiConsumer | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
| call | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | declare(strict_types=1); |
| 24 | |
| 25 | namespace oat\taoLti\controller; |
| 26 | |
| 27 | use oat\taoLti\models\classes\LtiUtils; |
| 28 | use common_exception_Error; |
| 29 | use common_exception_MissingParameter; |
| 30 | use common_http_Request; |
| 31 | use common_session_SessionManager; |
| 32 | use tao_actions_ServiceModule; |
| 33 | use tao_models_classes_oauth_Credentials; |
| 34 | use tao_models_classes_oauth_Service; |
| 35 | |
| 36 | class LtiConsumer extends tao_actions_ServiceModule |
| 37 | { |
| 38 | /** |
| 39 | * Launches a oauth tool |
| 40 | * @throws common_exception_Error |
| 41 | * @throws common_exception_MissingParameter |
| 42 | */ |
| 43 | public function call() |
| 44 | { |
| 45 | if (!$this->hasRequestParameter('ltiConsumerUri')) { |
| 46 | throw new common_exception_MissingParameter('ltiConsumerUri', get_class($this)); |
| 47 | } |
| 48 | if (!$this->hasRequestParameter('ltiLaunchUrl')) { |
| 49 | throw new common_exception_MissingParameter('ltiLaunchUrl', get_class($this)); |
| 50 | } |
| 51 | $ltiConsumer = new tao_models_classes_oauth_Credentials($this->getRequestParameter('ltiConsumerUri')); |
| 52 | $launchUrl = $this->getRequestParameter('ltiLaunchUrl'); |
| 53 | |
| 54 | $serviceCallId = $this->getServiceCallId() . '_c'; |
| 55 | |
| 56 | $session = common_session_SessionManager::getSession(); |
| 57 | |
| 58 | $roles = []; |
| 59 | foreach ($session->getUserRoles() as $role) { |
| 60 | foreach (LtiUtils::mapTaoRole2LTIRoles($role) as $ltiRole) { |
| 61 | $roles[] = $ltiRole; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | $ltiData = [ |
| 66 | 'lti_message_type' => 'basic-lti-launch-request', |
| 67 | 'lti_version' => 'LTI-1p0', |
| 68 | |
| 69 | 'resource_link_id' => rand(0, 9999999), |
| 70 | 'resource_link_title' => 'Launch Title', |
| 71 | 'resource_link_label' => 'Launch label', |
| 72 | |
| 73 | 'context_id' => $serviceCallId, |
| 74 | 'context_title' => 'Launch Title', |
| 75 | 'context_label' => 'Launch label', |
| 76 | |
| 77 | 'user_id' => $session->getUserUri(), |
| 78 | 'roles' => implode(',', $roles), |
| 79 | 'lis_person_name_full' => $session->getUserLabel(), |
| 80 | |
| 81 | 'tool_consumer_info_product_family_code' => PRODUCT_NAME, |
| 82 | 'tool_consumer_info_version' => TAO_VERSION |
| 83 | ]; |
| 84 | |
| 85 | // @todo add: |
| 86 | /* |
| 87 | user_id: |
| 88 | roles: |
| 89 | |
| 90 | lis_person_name_full: |
| 91 | lis_person_name_family: |
| 92 | lis_person_name_given: |
| 93 | lis_person_contact_email_primary: |
| 94 | lis_person_sourcedid: |
| 95 | |
| 96 | tool_consumer_info_product_family_code: |
| 97 | tool_consumer_info_version: |
| 98 | tool_consumer_instance_guid: |
| 99 | tool_consumer_instance_description: |
| 100 | */ |
| 101 | $request = new common_http_Request($launchUrl, common_http_Request::METHOD_POST, $ltiData); |
| 102 | $service = new tao_models_classes_oauth_Service(); |
| 103 | $signedRequest = $service->sign($request, $ltiConsumer); |
| 104 | |
| 105 | $this->setData('launchUrl', $launchUrl); |
| 106 | $this->setData('ltiData', $signedRequest->getParams()); |
| 107 | $this->setData('client_config_url', $this->getClientConfigUrl()); |
| 108 | $this->setView('ltiConsumer.tpl'); |
| 109 | } |
| 110 | } |