1
|
|
|
<?php namespace Nilesuan\OAuth2\Client\Provider; |
2
|
|
|
|
3
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
4
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
5
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
6
|
|
|
use League\OAuth2\Client\Tool\ArrayAccessorTrait; |
7
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
|
10
|
|
|
class Thirtysevensignals extends AbstractProvider |
11
|
|
|
{ |
12
|
|
|
use ArrayAccessorTrait, |
13
|
|
|
BearerAuthorizationTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Get authorization url to begin OAuth flow |
17
|
|
|
* |
18
|
|
|
* @return string |
19
|
|
|
*/ |
20
|
9 |
|
public function getBaseAuthorizationUrl() |
21
|
|
|
{ |
22
|
9 |
|
return 'https://launchpad.37signals.com/authorization/new'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Builds the authorization URL's query string. |
27
|
|
|
* |
28
|
|
|
* @param array $params Query parameters |
29
|
|
|
* @return string Query string |
30
|
|
|
*/ |
31
|
9 |
|
protected function getAuthorizationQuery(array $params) |
32
|
|
|
{ |
33
|
9 |
|
$params['type'] = 'web_server'; |
34
|
9 |
|
return $this->buildQueryString($params); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get access token url to retrieve token |
39
|
|
|
* |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
12 |
|
public function getBaseAccessTokenUrl(array $params) |
43
|
|
|
{ |
44
|
12 |
|
return 'https://launchpad.37signals.com/authorization/token'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns the request body for requesting an access token. |
49
|
|
|
* |
50
|
|
|
* @param array $params |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
9 |
|
protected function getAccessTokenBody(array $params) |
54
|
|
|
{ |
55
|
9 |
|
$params['type'] = ($params['grant_type'] === 'refresh_token') ? 'refresh' : 'web_server'; |
56
|
9 |
|
return $this->buildQueryString($params); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get provider url to fetch user details |
61
|
|
|
* |
62
|
|
|
* @param AccessToken $token |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
6 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
67
|
|
|
{ |
68
|
6 |
|
return 'https://launchpad.37signals.com/authorization.json'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the default scopes used by this provider. |
73
|
|
|
* |
74
|
|
|
* This should not be a complete list of all scopes, but the minimum |
75
|
|
|
* required for the provider user interface! |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
6 |
|
protected function getDefaultScopes() |
80
|
|
|
{ |
81
|
6 |
|
return []; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Check a provider response for errors. |
86
|
|
|
* |
87
|
|
|
* @throws IdentityProviderException |
88
|
|
|
* @param ResponseInterface $response |
89
|
|
|
* @param string $data Parsed response data |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
9 |
|
protected function checkResponse(ResponseInterface $response, $data) |
93
|
|
|
{ |
94
|
|
|
$errors = [ |
95
|
9 |
|
'error_description', |
96
|
6 |
|
'error.message', |
97
|
6 |
|
'error', |
98
|
6 |
|
]; |
99
|
|
|
|
100
|
9 |
|
array_map(function ($error) use ($response, $data) { |
101
|
9 |
|
if ($message = $this->getValueByKey($data, $error)) { |
|
|
|
|
102
|
3 |
|
throw new IdentityProviderException($message, $response->getStatusCode(), $response); |
|
|
|
|
103
|
|
|
} |
104
|
9 |
|
}, $errors); |
105
|
9 |
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Generate a user object from a successful user details request. |
109
|
|
|
* |
110
|
|
|
* @param object $response |
111
|
|
|
* @param AccessToken $token |
112
|
|
|
* @return ThirtysevensignalsResourceOwner |
113
|
|
|
*/ |
114
|
6 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
115
|
|
|
{ |
116
|
6 |
|
return new ThirtysevensignalsResourceOwner($response); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Returns a prepared request for requesting an access token. |
121
|
|
|
* |
122
|
|
|
* @param array $params Query string parameters |
123
|
|
|
* @return \GuzzleHttp\Psr7\Request |
124
|
|
|
*/ |
125
|
9 |
|
protected function getAccessTokenRequest(array $params) |
126
|
|
|
{ |
127
|
9 |
|
$request = parent::getAccessTokenRequest($params); |
128
|
9 |
|
$uri = $request->getUri() |
129
|
9 |
|
->withUserInfo($this->clientId, $this->clientSecret); |
130
|
|
|
|
131
|
9 |
|
return $request->withUri($uri); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
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: