1
|
|
|
<?php namespace Stevenmaguire\OAuth2\Client\Provider; |
2
|
|
|
|
3
|
|
|
use GuzzleHttp\Psr7\Uri; |
4
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
5
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
6
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
7
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
|
10
|
|
|
class Microsoft extends AbstractProvider |
11
|
|
|
{ |
12
|
|
|
use BearerAuthorizationTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default scopes |
16
|
|
|
* |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
public $defaultScopes = ['wl.basic', 'wl.emails']; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Base url for authorization. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $urlAuthorize = 'https://login.live.com/oauth20_authorize.srf'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Base url for access token. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $urlAccessToken = 'https://login.live.com/oauth20_token.srf'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Base url for resource owner. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $urlResourceOwnerDetails = 'https://graph.microsoft.com/v1.0/me'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get authorization url to begin OAuth flow |
44
|
|
|
* |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
12 |
|
public function getBaseAuthorizationUrl() |
48
|
|
|
{ |
49
|
12 |
|
return $this->urlAuthorize; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get access token url to retrieve token |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
15 |
|
public function getBaseAccessTokenUrl(array $params) |
58
|
|
|
{ |
59
|
15 |
|
return $this->urlAccessToken; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get default scopes |
64
|
|
|
* |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
9 |
|
protected function getDefaultScopes() |
68
|
|
|
{ |
69
|
9 |
|
return $this->defaultScopes; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Check a provider response for errors. |
74
|
|
|
* |
75
|
|
|
* @throws IdentityProviderException |
76
|
|
|
* @param ResponseInterface $response |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
9 |
|
protected function checkResponse(ResponseInterface $response, $data) |
80
|
|
|
{ |
81
|
9 |
|
if (isset($data['error'])) { |
82
|
3 |
|
throw new IdentityProviderException( |
83
|
3 |
|
(isset($data['error']['message']) ? $data['error']['message'] : $response->getReasonPhrase()), |
84
|
3 |
|
$response->getStatusCode(), |
85
|
2 |
|
$response |
|
|
|
|
86
|
1 |
|
); |
87
|
|
|
} |
88
|
6 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Generate a user object from a successful user details request. |
92
|
|
|
* |
93
|
|
|
* @param array $response |
94
|
|
|
* @param AccessToken $token |
95
|
|
|
* @return MicrosoftResourceOwner |
96
|
|
|
*/ |
97
|
|
|
protected function createResourceOwner(array $response, AccessToken $token) |
98
|
|
|
{ |
99
|
|
|
return new MicrosoftResourceOwner($response); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get provider url to fetch user details |
104
|
|
|
* |
105
|
|
|
* @param AccessToken $token |
106
|
|
|
* |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
6 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
110
|
|
|
{ |
111
|
6 |
|
$uri = new Uri($this->urlResourceOwnerDetails); |
112
|
|
|
|
113
|
6 |
|
return (string) Uri::withQueryValue($uri, 'access_token', (string) $token); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: