[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/auth/provider/oauth/service/ -> twitter.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\auth\provider\oauth\service;
  15  
  16  /**
  17  * Twitter OAuth service
  18  */
  19  class twitter extends \phpbb\auth\provider\oauth\service\base
  20  {
  21      /**
  22      * phpBB config
  23      *
  24      * @var \phpbb\config\config
  25      */
  26      protected $config;
  27  
  28      /**
  29      * phpBB request
  30      *
  31      * @var \phpbb\request\request_interface
  32      */
  33      protected $request;
  34  
  35      /**
  36      * Constructor
  37      *
  38      * @param    \phpbb\config\config                $config
  39      * @param    \phpbb\request\request_interface    $request
  40      */
  41  	public function __construct(\phpbb\config\config $config, \phpbb\request\request_interface $request)
  42      {
  43          $this->config = $config;
  44          $this->request = $request;
  45      }
  46  
  47      /**
  48      * {@inheritdoc}
  49      */
  50  	public function get_service_credentials()
  51      {
  52          return array(
  53              'key'        => $this->config['auth_oauth_twitter_key'],
  54              'secret'    => $this->config['auth_oauth_twitter_secret'],
  55          );
  56      }
  57  
  58      /**
  59      * {@inheritdoc}
  60      */
  61  	public function perform_auth_login()
  62      {
  63          if (!($this->service_provider instanceof \OAuth\OAuth1\Service\Twitter))
  64          {
  65              throw new \phpbb\auth\provider\oauth\service\exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE');
  66          }
  67  
  68          $storage = $this->service_provider->getStorage();
  69          $token = $storage->retrieveAccessToken('Twitter');
  70          $tokensecret = $token->getRequestTokenSecret();
  71  
  72          // This was a callback request from twitter, get the token
  73          $this->service_provider->requestAccessToken(
  74              $this->request->variable('oauth_token', ''),
  75              $this->request->variable('oauth_verifier', ''),
  76              $tokensecret
  77          );
  78  
  79          // Send a request with it
  80          $result = json_decode($this->service_provider->request('account/verify_credentials.json'), true);
  81  
  82          // Return the unique identifier returned from twitter
  83          return $result['id'];
  84      }
  85  
  86      /**
  87      * {@inheritdoc}
  88      */
  89  	public function perform_token_auth()
  90      {
  91          if (!($this->service_provider instanceof \OAuth\OAuth1\Service\Twitter))
  92          {
  93              throw new \phpbb\auth\provider\oauth\service\exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE');
  94          }
  95  
  96          // Send a request with it
  97          $result = json_decode($this->service_provider->request('account/verify_credentials.json'), true);
  98  
  99          // Return the unique identifier returned from twitter
 100          return $result['id'];
 101      }
 102  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1