Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 402] [Versions 310 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  class OAuthDataStore extends OAuth\OAuthDataStore
  17  {
  18  
  19  /**
  20   * Tool Provider object.
  21   *
  22   * @var ToolProvider $toolProvider
  23   */
  24      private $toolProvider = null;
  25  
  26  /**
  27   * Class constructor.
  28   *
  29   * @param ToolProvider $toolProvider Tool_Provider object
  30   */
  31      public function __construct($toolProvider)
  32      {
  33  
  34          $this->toolProvider = $toolProvider;
  35  
  36      }
  37  
  38  /**
  39   * Create an OAuthConsumer object for the tool consumer.
  40   *
  41   * @param string $consumerKey Consumer key value
  42   *
  43   * @return OAuthConsumer OAuthConsumer object
  44   */
  45      function lookup_consumer($consumerKey)
  46      {
  47  
  48          return new OAuth\OAuthConsumer($this->toolProvider->consumer->getKey(),
  49             $this->toolProvider->consumer->secret);
  50  
  51      }
  52  
  53  /**
  54   * Create an OAuthToken object for the tool consumer.
  55   *
  56   * @param string $consumer   OAuthConsumer object
  57   * @param string $tokenType  Token type
  58   * @param string $token      Token value
  59   *
  60   * @return OAuthToken OAuthToken object
  61   */
  62      function lookup_token($consumer, $tokenType, $token)
  63      {
  64  
  65          return new OAuth\OAuthToken($consumer, '');
  66  
  67      }
  68  
  69  /**
  70   * Lookup nonce value for the tool consumer.
  71   *
  72   * @param OAuthConsumer $consumer  OAuthConsumer object
  73   * @param string        $token     Token value
  74   * @param string        $value     Nonce value
  75   * @param string        $timestamp Date/time of request
  76   *
  77   * @return boolean True if the nonce value already exists
  78   */
  79      function lookup_nonce($consumer, $token, $value, $timestamp)
  80      {
  81  
  82          $nonce = new ConsumerNonce($this->toolProvider->consumer, $value);
  83          $ok = !$nonce->load();
  84          if ($ok) {
  85              $ok = $nonce->save();
  86          }
  87          if (!$ok) {
  88              $this->toolProvider->reason = 'Invalid nonce.';
  89          }
  90  
  91          return !$ok;
  92  
  93      }
  94  
  95  /**
  96   * Get new request token.
  97   *
  98   * @param OAuthConsumer $consumer  OAuthConsumer object
  99   * @param string        $callback  Callback URL
 100   *
 101   * @return string Null value
 102   */
 103      function new_request_token($consumer, $callback = null)
 104      {
 105  
 106          return null;
 107  
 108      }
 109  
 110  /**
 111   * Get new access token.
 112   *
 113   * @param string        $token     Token value
 114   * @param OAuthConsumer $consumer  OAuthConsumer object
 115   * @param string        $verifier  Verification code
 116   *
 117   * @return string Null value
 118   */
 119      function new_access_token($token, $consumer, $verifier = null)
 120      {
 121  
 122          return null;
 123  
 124      }
 125  
 126  }