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\Contracts\ConfigInterface as Config; |
10
|
|
|
|
11
|
|
|
abstract class AbstractProvider extends \Laravel\Socialite\Two\AbstractProvider implements ProviderInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
protected $credentialsResponseBody; |
17
|
|
|
|
18
|
1 |
|
public static function serviceContainerKey($providerName) |
19
|
|
|
{ |
20
|
1 |
|
return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName; |
21
|
|
|
} |
22
|
|
|
|
23
|
7 |
|
public static function additionalConfigKeys() |
24
|
|
|
{ |
25
|
7 |
|
return []; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param Config $config |
30
|
|
|
* |
31
|
|
|
* @return $this |
32
|
|
|
*/ |
33
|
1 |
|
public function config(Config $config) |
34
|
|
|
{ |
35
|
1 |
|
$config = $config->get(); |
36
|
1 |
|
$this->clientId = $config['client_id']; |
37
|
1 |
|
$this->redirectUrl = $config['redirect']; |
38
|
1 |
|
$this->clientSecret = $config['client_secret']; |
39
|
|
|
|
40
|
1 |
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return \SocialiteProviders\Manager\OAuth2\User |
45
|
|
|
*/ |
46
|
5 |
|
public function user() |
47
|
|
|
{ |
48
|
5 |
|
if ($this->hasInvalidState()) { |
49
|
2 |
|
throw new InvalidStateException(); |
50
|
|
|
} |
51
|
|
|
|
52
|
3 |
|
$user = $this->mapUserToObject($this->getUserByToken( |
53
|
3 |
|
$token = $this->getAccessToken($this->getCode()) |
|
|
|
|
54
|
3 |
|
)); |
55
|
|
|
|
56
|
3 |
|
$user->setToken($token); |
57
|
|
|
|
58
|
3 |
|
if ($user instanceof User) { |
59
|
3 |
|
return $user->setAccessTokenResponseBody($this->credentialsResponseBody); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $user; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the access token for the given code. |
67
|
|
|
* |
68
|
|
|
* @param string $code |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
3 |
|
public function getAccessToken($code) |
73
|
|
|
{ |
74
|
3 |
|
$postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body'; |
75
|
|
|
|
76
|
3 |
|
$response = $this->getHttpClient()->post($this->getTokenUrl(), [ |
77
|
3 |
|
'headers' => ['Accept' => 'application/json'], |
78
|
3 |
|
$postKey => $this->getTokenFields($code), |
79
|
3 |
|
]); |
80
|
|
|
|
81
|
3 |
|
$this->credentialsResponseBody = json_decode($response->getBody(), true); |
|
|
|
|
82
|
|
|
|
83
|
3 |
|
return $this->parseAccessToken($response->getBody()); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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.