Blame view

common/components/nodge/eauth/src/services/LiveOAuth2Service.php 2.66 KB
b0f143c3   Yarik   first 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  <?php
  /**
   * LiveOAuth2Service class file.
   *
   * Register application: https://account.live.com/developers/applications/index
   *
   * @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\OAuth2\Service\ServiceInterface;
  use nodge\eauth\oauth2\Service;
  
  /**
   * Microsoft Live provider class.
   *
   * @package application.extensions.eauth.services
   */
  class LiveOAuth2Service extends Service
  {
  
  	const SCOPE_BASIC = 'wl.basic';
  	const SCOPE_OFFLINE = 'wl.offline_access';
  	const SCOPE_SIGNIN = 'wl.signin';
  	const SCOPE_BIRTHDAY = 'wl.birthday';
  	const SCOPE_CALENDARS = 'wl.calendars';
  	const SCOPE_CALENDARS_UPDATE = 'wl.calendars_update';
  	const SCOPE_CONTACTS_BIRTHDAY = 'wl.contacts_birthday';
  	const SCOPE_CONTACTS_CREATE = 'wl.contacts_create';
  	const SCOPE_CONTACTS_CALENDARS = 'wl.contacts_calendars';
  	const SCOPE_CONTACTS_PHOTOS = 'wl.contacts_photos';
  	const SCOPE_CONTACTS_SKYDRIVE = 'wl.contacts_skydrive';
  	const SCOPE_EMAILS = 'wl.emails';
  	const sCOPE_EVENTS_CREATE = 'wl.events_create';
  	const SCOPE_MESSENGER = 'wl.messenger';
  	const SCOPE_PHONE_NUMBERS = 'wl.phone_numbers';
  	const SCOPE_PHOTOS = 'wl.photos';
  	const SCOPE_POSTAL_ADDRESSES = 'wl.postal_addresses';
  	const SCOPE_SHARE = 'wl.share';
  	const SCOPE_SKYDRIVE = 'wl.skydrive';
  	const SCOPE_SKYDRIVE_UPDATE = 'wl.skydrive_update';
  	const SCOPE_WORK_PROFILE = 'wl.work_profile';
  	const SCOPE_APPLICATIONS = 'wl.applications';
  	const SCOPE_APPLICATIONS_CREATE = 'wl.applications_create';
  
  	protected $name = 'live';
  	protected $title = 'Live';
  	protected $type = 'OAuth2';
  	protected $jsArguments = ['popup' => ['width' => 500, 'height' => 600]];
  
  	protected $scopes = [self::SCOPE_BASIC];
  	protected $providerOptions = [
  		'authorize' => 'https://login.live.com/oauth20_authorize.srf',
  		'access_token' => 'https://login.live.com/oauth20_token.srf',
  	];
  	protected $baseApiUrl = 'https://apis.live.net/v5.0/';
  
  	protected function fetchAttributes()
  	{
  		$info = $this->makeSignedRequest('me');
  
  		$this->attributes['id'] = $info['id'];
  		$this->attributes['name'] = $info['name'];
  		$this->attributes['url'] = 'https://profile.live.com/cid-' . $info['id'] . '/';
  
  		$this->attributes['email'] = $info['emails']['account'];
  		$this->attributes['first_name'] = $info['first_name'];
  		$this->attributes['last_name'] = $info['last_name'];
  		$this->attributes['gender'] = $info['gender'];
  		$this->attributes['locale'] = $info['locale'];
  
  		return true;
  	}
  
  	/**
  	 * @return int
  	 */
  	public function getAuthorizationMethod()
  	{
  		return ServiceInterface::AUTHORIZATION_METHOD_QUERY_STRING;
  	}
  }