1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: xiabin |
5
|
|
|
* Date: 16/6/24 |
6
|
|
|
* Time: 下午7:12 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Xiabin\OAuth2\Client\Provider; |
11
|
|
|
|
12
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
13
|
|
|
use Psr\Http\Message\ResponseInterface; |
14
|
|
|
use GuzzleHttp\Client as HttpClient; |
15
|
|
|
use Xiabin\OAuth2\Client\Provider\Exception; |
16
|
|
|
use Xiabin\OAuth2\Client\Provider\Exception\SinaWeiboIdentityProviderException; |
17
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class SinaWeibo |
21
|
|
|
* @package League\OAuth2\Client\Provider |
22
|
|
|
*/ |
23
|
|
|
class SinaWeibo extends AbstractProvider |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Returns the base URL for authorizing a client. |
29
|
|
|
* |
30
|
|
|
* Eg. https://oauth.service.com/authorize |
31
|
|
|
* |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
6 |
|
public function getBaseAuthorizationUrl() |
35
|
|
|
{ |
36
|
6 |
|
return "https://api.weibo.com/oauth2/authorize"; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Returns the base URL for requesting an access token. |
41
|
|
|
* |
42
|
|
|
* Eg. https://oauth.service.com/token |
43
|
|
|
* |
44
|
|
|
* @param array $params |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
12 |
|
public function getBaseAccessTokenUrl(array $params) |
48
|
|
|
{ |
49
|
12 |
|
return 'https://api.weibo.com/oauth2/access_token?' . http_build_query([ |
50
|
12 |
|
'client_id' => $params['client_id'], |
51
|
12 |
|
'client_secret' => $params['client_secret'], |
52
|
12 |
|
'grant_type' => $params['grant_type'], |
53
|
12 |
|
'redirect_uri' => $params['redirect_uri'], |
54
|
12 |
|
'code' => $params['code'] |
55
|
8 |
|
]); |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns the URL for requesting the resource owner's details. |
61
|
|
|
* |
62
|
|
|
* @param AccessToken $token |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
66
|
|
|
{ |
67
|
|
|
// 暂不使用 |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns the default scopes used by this provider. |
73
|
|
|
* |
74
|
|
|
* This should only be the scopes that are required to request the details |
75
|
|
|
* of the resource owner, rather than all the available scopes. |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
6 |
|
protected function getDefaultScopes() |
80
|
|
|
{ |
81
|
|
|
// 暂不使用 |
82
|
6 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Checks a provider response for errors. |
86
|
|
|
* @param ResponseInterface $response |
87
|
|
|
* @param array|string $data |
88
|
|
|
* @throws \League\OAuth2\Client\Provider\Exception\IdentityProviderException |
89
|
|
|
*/ |
90
|
9 |
|
protected function checkResponse(ResponseInterface $response, $data) |
91
|
|
|
{ |
92
|
9 |
|
if ($response->getStatusCode() >= 400) { |
93
|
3 |
|
throw SinaWeiboIdentityProviderException::clientException($response, $data); |
|
|
|
|
94
|
6 |
|
} elseif (isset($data['error'])) { |
95
|
3 |
|
throw SinaWeiboIdentityProviderException::oauthException($response, $data); |
|
|
|
|
96
|
|
|
} |
97
|
3 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Generates a resource owner object from a successful resource owner |
101
|
|
|
* details request. |
102
|
|
|
* |
103
|
|
|
* @param array $response |
104
|
|
|
* @param AccessToken $token |
105
|
|
|
* @return \League\OAuth2\Client\Provider\ResourceOwnerInterface |
106
|
|
|
*/ |
107
|
|
|
protected function createResourceOwner(array $response, AccessToken $token) |
108
|
|
|
{ |
109
|
|
|
// 暂不使用. |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.