Blame view

common/components/nodge/eauth/src/services/TwitterOAuth1Service.php 1.94 KB
14a09168   Alex Savenko   init commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  <?php

  /**

   * TwitterOAuthService class file.

   *

   * Register application: https://dev.twitter.com/apps/new

   *

   * @author Maxim Zemskov <nodge@yandex.ru>

   * @link http://github.com/Nodge/yii2-eauth/

   * @license http://www.opensource.org/licenses/bsd-license.php

   */

  

  namespace common\components\nodge\eauth\src\services;

  

  use OAuth\OAuth1\Token\TokenInterface;

  use nodge\eauth\oauth1\Service;

  

  

  /**

   * Twitter provider class.

   *

   * @package application.extensions.eauth.services

   */

  class TwitterOAuth1Service extends Service

  {

  

  	protected $name = 'twitter';

  	protected $title = 'Twitter';

  	protected $type = 'OAuth1';

  	protected $jsArguments = ['popup' => ['width' => 900, 'height' => 550]];

  

  	protected $providerOptions = [

  		'request' => 'https://api.twitter.com/oauth/request_token',

  		'authorize' => 'https://api.twitter.com/oauth/authenticate', //https://api.twitter.com/oauth/authorize

  		'access' => 'https://api.twitter.com/oauth/access_token',

  	];

  	protected $baseApiUrl = 'https://api.twitter.com/1.1/';

  	protected $tokenDefaultLifetime = TokenInterface::EOL_NEVER_EXPIRES;

  

  	/**

  	 * @return bool

  	 */

  	protected function fetchAttributes()

  	{

  		$info = $this->makeSignedRequest('account/verify_credentials.json');

  

  		$this->attributes['id'] = $info['id'];

  		$this->attributes['name'] = $info['name'];

  		$this->attributes['url'] = 'http://twitter.com/account/redirect_by_id?id=' . $info['id_str'];

  

  		$this->attributes['username'] = $info['screen_name'];

  		$this->attributes['language'] = $info['lang'];

  		$this->attributes['timezone'] = timezone_name_from_abbr('', $info['utc_offset'], date('I'));

  		$this->attributes['photo'] = $info['profile_image_url'];

  

  		return true;

  	}

  

  	/**

  	 * Authenticate the user.

  	 *

  	 * @return boolean whether user was successfuly authenticated.

  	 */

  	public function authenticate()

  	{

  		if (isset($_GET['denied'])) {

  			$this->cancel();

  		}

  

  		return parent::authenticate();

  	}

  }