MDL-81717 h5p: Improve robustness content type fetching
[moodle.git] / mod / lti / TrivialStore.php
blobcc4765f272549cb3d52f92ac02c41c7db27e9040
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle 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.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 // This file is part of BasicLTI4Moodle
19 // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)
20 // consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web
21 // based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI
22 // specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS
23 // are already supporting or going to support BasicLTI. This project Implements the consumer
24 // for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.
25 // BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem
26 // at the GESSI research group at UPC.
27 // SimpleLTI consumer for Moodle is an implementation of the early specification of LTI
28 // by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a
29 // Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.
31 // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis
32 // of the Universitat Politecnica de Catalunya http://www.upc.edu
33 // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu.
35 /**
36 * This file contains a Trivial memory-based store - no support for tokens
38 * @package mod_lti
39 * @copyright IMS Global Learning Consortium
41 * @author Charles Severance csev@umich.edu
43 * @license http://www.apache.org/licenses/LICENSE-2.0
46 namespace moodle\mod\lti; // Using a namespace as the basicLTI module imports classes with the same names.
48 defined('MOODLE_INTERNAL') || die;
50 /**
51 * A Trivial memory-based store - no support for tokens.
53 class TrivialOAuthDataStore extends OAuthDataStore {
55 /** @var array $consumers Array of tool consumer keys and secrets */
56 private $consumers = array();
58 /**
59 * Add a consumer to the array
61 * @param string $consumerkey Consumer key
62 * @param string $consumersecret Consumer secret
64 public function add_consumer($consumerkey, $consumersecret) {
65 $this->consumers[$consumerkey] = $consumersecret;
68 /**
69 * Get OAuth consumer given its key
71 * @param string $consumerkey Consumer key
73 * @return moodle\mod\lti\OAuthConsumer OAuthConsumer object
75 public function lookup_consumer($consumerkey) {
76 if (strpos($consumerkey, "http://" ) === 0) {
77 $consumer = new OAuthConsumer($consumerkey, "secret", null);
78 return $consumer;
80 if ( $this->consumers[$consumerkey] ) {
81 $consumer = new OAuthConsumer($consumerkey, $this->consumers[$consumerkey], null);
82 return $consumer;
84 return null;
87 /**
88 * Create a dummy OAuthToken object for a consumer
90 * @param moodle\mod\lti\OAuthConsumer $consumer Consumer
91 * @param string $tokentype Type of token
92 * @param string $token Token ID
94 * @return moodle\mod\lti\OAuthToken OAuthToken object
96 public function lookup_token($consumer, $tokentype, $token) {
97 return new OAuthToken($consumer, '');
101 * Nonce values are not checked so just return a null
103 * @param moodle\mod\lti\OAuthConsumer $consumer Consumer
104 * @param string $token Token ID
105 * @param string $nonce Nonce value
106 * @param string $timestamp Timestamp
108 * @return null
110 public function lookup_nonce($consumer, $token, $nonce, $timestamp) {
111 // Should add some clever logic to keep nonces from
112 // being reused - for now we are really trusting
113 // that the timestamp will save us.
114 return null;
118 * Tokens are not used so just return a null.
120 * @param moodle\mod\lti\OAuthConsumer $consumer Consumer
122 * @return null
124 public function new_request_token($consumer) {
125 return null;
129 * Tokens are not used so just return a null.
131 * @param string $token Token ID
132 * @param moodle\mod\lti\OAuthConsumer $consumer Consumer
134 * @return null
136 public function new_access_token($token, $consumer) {
137 return null;