Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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.
  13  //
  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/>.
  16  //
  17  // This file is part of BasicLTI4Moodle
  18  //
  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.
  30  //
  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.
  34  
  35  /**
  36   * This file contains a Trivial memory-based store - no support for tokens
  37   *
  38   * @package mod_lti
  39   * @copyright IMS Global Learning Consortium
  40   *
  41   * @author Charles Severance csev@umich.edu
  42   *
  43   * @license http://www.apache.org/licenses/LICENSE-2.0
  44   */
  45  
  46  namespace moodle\mod\lti; // Using a namespace as the basicLTI module imports classes with the same names.
  47  
  48  defined('MOODLE_INTERNAL') || die;
  49  
  50  /**
  51   * A Trivial memory-based store - no support for tokens.
  52   */
  53  class TrivialOAuthDataStore extends OAuthDataStore {
  54  
  55      /** @var array $consumers  Array of tool consumer keys and secrets */
  56      private $consumers = array();
  57  
  58      /**
  59       * Add a consumer to the array
  60       *
  61       * @param string $consumerkey     Consumer key
  62       * @param string $consumersecret  Consumer secret
  63       */
  64      public function add_consumer($consumerkey, $consumersecret) {
  65          $this->consumers[$consumerkey] = $consumersecret;
  66      }
  67  
  68      /**
  69       * Get OAuth consumer given its key
  70       *
  71       * @param string $consumerkey     Consumer key
  72       *
  73       * @return moodle\mod\lti\OAuthConsumer  OAuthConsumer object
  74       */
  75      public function lookup_consumer($consumerkey) {
  76          if (strpos($consumerkey, "http://" ) === 0) {
  77              $consumer = new OAuthConsumer($consumerkey, "secret", null);
  78              return $consumer;
  79          }
  80          if ( $this->consumers[$consumerkey] ) {
  81              $consumer = new OAuthConsumer($consumerkey, $this->consumers[$consumerkey], null);
  82              return $consumer;
  83          }
  84          return null;
  85      }
  86  
  87      /**
  88       * Create a dummy OAuthToken object for a consumer
  89       *
  90       * @param moodle\mod\lti\OAuthConsumer $consumer     Consumer
  91       * @param string $tokentype    Type of token
  92       * @param string $token        Token ID
  93       *
  94       * @return moodle\mod\lti\OAuthToken OAuthToken object
  95       */
  96      public function lookup_token($consumer, $tokentype, $token) {
  97          return new OAuthToken($consumer, '');
  98      }
  99  
 100      /**
 101       * Nonce values are not checked so just return a null
 102       *
 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
 107       *
 108       * @return null
 109       */
 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;
 115      }
 116  
 117      /**
 118       * Tokens are not used so just return a null.
 119       *
 120       * @param moodle\mod\lti\OAuthConsumer $consumer     Consumer
 121       *
 122       * @return null
 123       */
 124      public function new_request_token($consumer) {
 125          return null;
 126      }
 127  
 128      /**
 129       * Tokens are not used so just return a null.
 130       *
 131       * @param string $token        Token ID
 132       * @param moodle\mod\lti\OAuthConsumer $consumer     Consumer
 133       *
 134       * @return null
 135       */
 136      public function new_access_token($token, $consumer) {
 137          return null;
 138      }
 139  }