1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SocialiteProviders\Manager\OAuth2; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\ClientInterface; |
6
|
|
|
use Laravel\Socialite\Two\InvalidStateException; |
7
|
|
|
use SocialiteProviders\Manager\Contracts\OAuth2\ProviderInterface; |
8
|
|
|
use SocialiteProviders\Manager\SocialiteWasCalled; |
9
|
|
|
use SocialiteProviders\Manager\ConfigTrait; |
10
|
|
|
|
11
|
|
|
abstract class AbstractProvider extends \Laravel\Socialite\Two\AbstractProvider implements ProviderInterface |
12
|
|
|
{ |
13
|
|
|
use ConfigTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
1 |
|
protected $credentialsResponseBody; |
19
|
|
|
|
20
|
1 |
|
public static function serviceContainerKey($providerName) |
21
|
|
|
{ |
22
|
|
|
return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName; |
23
|
7 |
|
} |
24
|
|
|
|
25
|
7 |
|
/** |
26
|
|
|
* @return \SocialiteProviders\Manager\OAuth2\User |
27
|
|
|
*/ |
28
|
|
|
public function user() |
29
|
|
|
{ |
30
|
|
|
if ($this->hasInvalidState()) { |
31
|
|
|
throw new InvalidStateException(); |
32
|
|
|
} |
33
|
1 |
|
|
34
|
|
|
$user = $this->mapUserToObject($this->getUserByToken( |
35
|
1 |
|
$token = $this->getAccessToken($this->getCode()) |
|
|
|
|
36
|
1 |
|
)); |
37
|
1 |
|
|
38
|
1 |
|
$user->setToken($token); |
39
|
|
|
|
40
|
1 |
|
if ($user instanceof User) { |
41
|
|
|
return $user->setAccessTokenResponseBody($this->credentialsResponseBody); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $user; |
45
|
|
|
} |
46
|
5 |
|
|
47
|
|
|
/** |
48
|
5 |
|
* Get the access token for the given code. |
49
|
2 |
|
* |
50
|
|
|
* @param string $code |
51
|
|
|
* |
52
|
3 |
|
* @return string |
53
|
3 |
|
*/ |
54
|
3 |
|
public function getAccessToken($code) |
55
|
|
|
{ |
56
|
3 |
|
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body'; |
57
|
|
|
|
58
|
3 |
|
$response = $this->getHttpClient()->post($this->getTokenUrl(), [ |
59
|
3 |
|
'headers' => ['Accept' => 'application/json'], |
60
|
|
|
$postKey => $this->getTokenFields($code), |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
$this->credentialsResponseBody = json_decode($response->getBody(), true); |
|
|
|
|
64
|
|
|
|
65
|
|
|
return $this->parseAccessToken($response->getBody()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
This check looks at variables that 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.