Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

   1  <?php
   2  
   3  namespace IMSGlobal\LTI\ToolProvider;
   4  
   5  use IMSGlobal\LTI\OAuth;
   6  
   7  /**
   8   * Class to represent an OAuth datastore
   9   *
  10   * @author  Stephen P Vickers <svickers@imsglobal.org>
  11   * @copyright  IMS Global Learning Consortium Inc
  12   * @date  2016
  13   * @version 3.0.2
  14   * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  15   */
  16  #[\AllowDynamicProperties]
  17  class OAuthDataStore extends OAuth\OAuthDataStore
  18  {
  19  
  20  /**
  21   * Tool Provider object.
  22   *
  23   * @var ToolProvider $toolProvider
  24   */
  25      private $toolProvider = null;
  26  
  27  /**
  28   * Class constructor.
  29   *
  30   * @param ToolProvider $toolProvider Tool_Provider object
  31   */
  32      public function __construct($toolProvider)
  33      {
  34  
  35          $this->toolProvider = $toolProvider;
  36  
  37      }
  38  
  39  /**
  40   * Create an OAuthConsumer object for the tool consumer.
  41   *
  42   * @param string $consumerKey Consumer key value
  43   *
  44   * @return OAuthConsumer OAuthConsumer object
  45   */
  46      function lookup_consumer($consumerKey)
  47      {
  48  
  49          return new OAuth\OAuthConsumer($this->toolProvider->consumer->getKey(),
  50             $this->toolProvider->consumer->secret);
  51  
  52      }
  53  
  54  /**
  55   * Create an OAuthToken object for the tool consumer.
  56   *
  57   * @param string $consumer   OAuthConsumer object
  58   * @param string $tokenType  Token type
  59   * @param string $token      Token value
  60   *
  61   * @return OAuthToken OAuthToken object
  62   */
  63      function lookup_token($consumer, $tokenType, $token)
  64      {
  65  
  66          return new OAuth\OAuthToken($consumer, '');
  67  
  68      }
  69  
  70  /**
  71   * Lookup nonce value for the tool consumer.
  72   *
  73   * @param OAuthConsumer $consumer  OAuthConsumer object
  74   * @param string        $token     Token value
  75   * @param string        $value     Nonce value
  76   * @param string        $timestamp Date/time of request
  77   *
  78   * @return boolean True if the nonce value already exists
  79   */
  80      function lookup_nonce($consumer, $token, $value, $timestamp)
  81      {
  82  
  83          $nonce = new ConsumerNonce($this->toolProvider->consumer, $value);
  84          $ok = !$nonce->load();
  85          if ($ok) {
  86              $ok = $nonce->save();
  87          }
  88          if (!$ok) {
  89              $this->toolProvider->reason = 'Invalid nonce.';
  90          }
  91  
  92          return !$ok;
  93  
  94      }
  95  
  96  /**
  97   * Get new request token.
  98   *
  99   * @param OAuthConsumer $consumer  OAuthConsumer object
 100   * @param string        $callback  Callback URL
 101   *
 102   * @return string Null value
 103   */
 104      function new_request_token($consumer, $callback = null)
 105      {
 106  
 107          return null;
 108  
 109      }
 110  
 111  /**
 112   * Get new access token.
 113   *
 114   * @param string        $token     Token value
 115   * @param OAuthConsumer $consumer  OAuthConsumer object
 116   * @param string        $verifier  Verification code
 117   *
 118   * @return string Null value
 119   */
 120      function new_access_token($token, $consumer, $verifier = null)
 121      {
 122  
 123          return null;
 124  
 125      }
 126  
 127  }