Completed
Branch develop (14b677)
by
unknown
13:21
created
htdocs/includes/OAuth/OAuth2/Service/Microsoft.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -12,131 +12,131 @@
 block discarded – undo
12 12
 
13 13
 class Microsoft extends AbstractService
14 14
 {
15
-    const SCOPE_BASIC = 'basic';
16
-    const SCOPE_OFFLINE_ACCESS = 'offline_access';
17
-    const SCOPE_SIGNIN = 'signin';
18
-    const SCOPE_BIRTHDAY = 'birthday';
19
-    const SCOPE_CALENDARS = 'calendars';
20
-    const SCOPE_CALENDARS_UPDATE = 'calendars_update';
21
-    const SCOPE_CONTACTS_BIRTHDAY = 'contacts_birthday';
22
-    const SCOPE_CONTACTS_CREATE = 'contacts_create';
23
-    const SCOPE_CONTACTS_CALENDARS = 'contacts_calendars';
24
-    const SCOPE_CONTACTS_PHOTOS = 'contacts_photos';
25
-    const SCOPE_CONTACTS_SKYDRIVE = 'contacts_skydrive';
26
-    const SCOPE_EMAIL = 'email';
27
-    const SCOPE_EVENTS_CREATE = 'events_create';
28
-    const SCOPE_MESSENGER = 'messenger';
29
-    const SCOPE_OPENID = 'openid';
30
-    const SCOPE_PHONE_NUMBERS = 'phone_numbers';
31
-    const SCOPE_PHOTOS = 'photos';
32
-    const SCOPE_POSTAL_ADDRESSES = 'postal_addresses';
33
-    const SCOPE_PROFILE = 'profile';
34
-    const SCOPE_SHARE = 'share';
35
-    const SCOPE_SKYDRIVE = 'skydrive';
36
-    const SCOPE_SKYDRIVE_UPDATE = 'skydrive_update';
37
-    const SCOPE_WORK_PROFILE = 'work_profile';
38
-    const SCOPE_APPLICATIONS = 'applications';
39
-    const SCOPE_APPLICATIONS_CREATE = 'applications_create';
40
-    const SCOPE_IMAP = 'imap';
41
-    const SCOPE_IMAP_ACCESSASUSERALL = 'https://outlook.office365.com/IMAP.AccessAsUser.All';
42
-    const SCOPE_SMTPSEND = 'https://outlook.office365.com/SMTP.Send';
43
-    const SCOPE_USERREAD = 'User.Read';
44
-    const SCOPE_MAILREAD = 'Mail.Read';
45
-    const SCOPE_MAILSEND = 'Mail.Send';
46
-
47
-    protected $storage;
48
-
49
-
50
-    /**
51
-     * MS uses some magical not officialy supported scope to get even moar info like full emailaddresses.
52
-     * They agree that giving 3rd party apps access to 3rd party emailaddresses is a pretty lame thing to do so in all
53
-     * their wisdom they added this scope because fuck you that's why.
54
-     *
55
-     * https://github.com/Lusitanian/PHPoAuthLib/issues/214
56
-     * http://social.msdn.microsoft.com/Forums/live/en-US/c6dcb9ab-aed4-400a-99fb-5650c393a95d/how-retrieve-users-
57
-     *                                  contacts-email-address?forum=messengerconnect
58
-     *
59
-     * Considering this scope is not officially supported: use with care
60
-     */
61
-    const SCOPE_CONTACTS_EMAILS = 'contacts_emails';
62
-
63
-
64
-    public function __construct(
65
-        CredentialsInterface $credentials,
66
-        ClientInterface $httpClient,
67
-        TokenStorageInterface $storage,
68
-        $scopes = array(),
69
-        UriInterface $baseApiUri = null
70
-    ) {
71
-        parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
72
-
73
-        $this->storage = $storage;
74
-
75
-        if (null === $baseApiUri) {
76
-            $this->baseApiUri = new Uri('https://apis.live.net/v5.0/');
77
-        }
78
-    }
79
-
80
-    /**
81
-     * {@inheritdoc}
82
-     */
83
-    public function getAuthorizationEndpoint()
84
-    {
85
-    	$tenant = $this->storage->getTenant();
86
-
87
-    	//return new Uri('https://login.live.com/oauth20_authorize.srf');
88
-        //return new Uri('https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize');
89
-        return new Uri('https://login.microsoftonline.com/'.$tenant.'/oauth2/v2.0/authorize');
90
-    }
91
-
92
-    /**
93
-     * {@inheritdoc}
94
-     */
95
-    public function getAccessTokenEndpoint()
96
-    {
97
-    	$tenant = $this->storage->getTenant();
98
-
99
-        //return new Uri('https://login.live.com/oauth20_token.srf');
100
-        //return new Uri('https://login.microsoftonline.com/organizations/oauth2/v2.0/token');
101
-        return new Uri('https://login.microsoftonline.com/'.$tenant.'/oauth2/v2.0/token');
102
-    }
103
-
104
-    /**
105
-     * {@inheritdoc}
106
-     */
107
-    public function getAuthorizationMethod()
108
-    {
109
-        return static::AUTHORIZATION_METHOD_QUERY_STRING;
110
-    }
111
-
112
-    /**
113
-     * {@inheritdoc}
114
-     */
115
-    protected function parseAccessTokenResponse($responseBody)
116
-    {
117
-        $data = json_decode($responseBody, true);
118
-
119
-        if (null === $data || !is_array($data)) {
120
-            throw new TokenResponseException('Unable to parse response.');
121
-        } elseif (isset($data['error'])) {
122
-            throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
123
-        }
124
-        //print $data['access_token'];exit;
125
-
126
-        $token = new StdOAuth2Token();
127
-        $token->setAccessToken($data['access_token']);
128
-        $token->setLifetime($data['expires_in']);
129
-
130
-        if (isset($data['refresh_token'])) {
131
-            $token->setRefreshToken($data['refresh_token']);
132
-            unset($data['refresh_token']);
133
-        }
134
-
135
-        unset($data['access_token']);
136
-        unset($data['expires_in']);
137
-
138
-        $token->setExtraParams($data);
139
-
140
-        return $token;
141
-    }
15
+	const SCOPE_BASIC = 'basic';
16
+	const SCOPE_OFFLINE_ACCESS = 'offline_access';
17
+	const SCOPE_SIGNIN = 'signin';
18
+	const SCOPE_BIRTHDAY = 'birthday';
19
+	const SCOPE_CALENDARS = 'calendars';
20
+	const SCOPE_CALENDARS_UPDATE = 'calendars_update';
21
+	const SCOPE_CONTACTS_BIRTHDAY = 'contacts_birthday';
22
+	const SCOPE_CONTACTS_CREATE = 'contacts_create';
23
+	const SCOPE_CONTACTS_CALENDARS = 'contacts_calendars';
24
+	const SCOPE_CONTACTS_PHOTOS = 'contacts_photos';
25
+	const SCOPE_CONTACTS_SKYDRIVE = 'contacts_skydrive';
26
+	const SCOPE_EMAIL = 'email';
27
+	const SCOPE_EVENTS_CREATE = 'events_create';
28
+	const SCOPE_MESSENGER = 'messenger';
29
+	const SCOPE_OPENID = 'openid';
30
+	const SCOPE_PHONE_NUMBERS = 'phone_numbers';
31
+	const SCOPE_PHOTOS = 'photos';
32
+	const SCOPE_POSTAL_ADDRESSES = 'postal_addresses';
33
+	const SCOPE_PROFILE = 'profile';
34
+	const SCOPE_SHARE = 'share';
35
+	const SCOPE_SKYDRIVE = 'skydrive';
36
+	const SCOPE_SKYDRIVE_UPDATE = 'skydrive_update';
37
+	const SCOPE_WORK_PROFILE = 'work_profile';
38
+	const SCOPE_APPLICATIONS = 'applications';
39
+	const SCOPE_APPLICATIONS_CREATE = 'applications_create';
40
+	const SCOPE_IMAP = 'imap';
41
+	const SCOPE_IMAP_ACCESSASUSERALL = 'https://outlook.office365.com/IMAP.AccessAsUser.All';
42
+	const SCOPE_SMTPSEND = 'https://outlook.office365.com/SMTP.Send';
43
+	const SCOPE_USERREAD = 'User.Read';
44
+	const SCOPE_MAILREAD = 'Mail.Read';
45
+	const SCOPE_MAILSEND = 'Mail.Send';
46
+
47
+	protected $storage;
48
+
49
+
50
+	/**
51
+	 * MS uses some magical not officialy supported scope to get even moar info like full emailaddresses.
52
+	 * They agree that giving 3rd party apps access to 3rd party emailaddresses is a pretty lame thing to do so in all
53
+	 * their wisdom they added this scope because fuck you that's why.
54
+	 *
55
+	 * https://github.com/Lusitanian/PHPoAuthLib/issues/214
56
+	 * http://social.msdn.microsoft.com/Forums/live/en-US/c6dcb9ab-aed4-400a-99fb-5650c393a95d/how-retrieve-users-
57
+	 *                                  contacts-email-address?forum=messengerconnect
58
+	 *
59
+	 * Considering this scope is not officially supported: use with care
60
+	 */
61
+	const SCOPE_CONTACTS_EMAILS = 'contacts_emails';
62
+
63
+
64
+	public function __construct(
65
+		CredentialsInterface $credentials,
66
+		ClientInterface $httpClient,
67
+		TokenStorageInterface $storage,
68
+		$scopes = array(),
69
+		UriInterface $baseApiUri = null
70
+	) {
71
+		parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
72
+
73
+		$this->storage = $storage;
74
+
75
+		if (null === $baseApiUri) {
76
+			$this->baseApiUri = new Uri('https://apis.live.net/v5.0/');
77
+		}
78
+	}
79
+
80
+	/**
81
+	 * {@inheritdoc}
82
+	 */
83
+	public function getAuthorizationEndpoint()
84
+	{
85
+		$tenant = $this->storage->getTenant();
86
+
87
+		//return new Uri('https://login.live.com/oauth20_authorize.srf');
88
+		//return new Uri('https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize');
89
+		return new Uri('https://login.microsoftonline.com/'.$tenant.'/oauth2/v2.0/authorize');
90
+	}
91
+
92
+	/**
93
+	 * {@inheritdoc}
94
+	 */
95
+	public function getAccessTokenEndpoint()
96
+	{
97
+		$tenant = $this->storage->getTenant();
98
+
99
+		//return new Uri('https://login.live.com/oauth20_token.srf');
100
+		//return new Uri('https://login.microsoftonline.com/organizations/oauth2/v2.0/token');
101
+		return new Uri('https://login.microsoftonline.com/'.$tenant.'/oauth2/v2.0/token');
102
+	}
103
+
104
+	/**
105
+	 * {@inheritdoc}
106
+	 */
107
+	public function getAuthorizationMethod()
108
+	{
109
+		return static::AUTHORIZATION_METHOD_QUERY_STRING;
110
+	}
111
+
112
+	/**
113
+	 * {@inheritdoc}
114
+	 */
115
+	protected function parseAccessTokenResponse($responseBody)
116
+	{
117
+		$data = json_decode($responseBody, true);
118
+
119
+		if (null === $data || !is_array($data)) {
120
+			throw new TokenResponseException('Unable to parse response.');
121
+		} elseif (isset($data['error'])) {
122
+			throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
123
+		}
124
+		//print $data['access_token'];exit;
125
+
126
+		$token = new StdOAuth2Token();
127
+		$token->setAccessToken($data['access_token']);
128
+		$token->setLifetime($data['expires_in']);
129
+
130
+		if (isset($data['refresh_token'])) {
131
+			$token->setRefreshToken($data['refresh_token']);
132
+			unset($data['refresh_token']);
133
+		}
134
+
135
+		unset($data['access_token']);
136
+		unset($data['expires_in']);
137
+
138
+		$token->setExtraParams($data);
139
+
140
+		return $token;
141
+	}
142 142
 }
Please login to merge, or discard this patch.