|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SocialiteProviders\Manager\OAuth2; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
|
6
|
|
|
use Laravel\Socialite\Two\InvalidStateException; |
|
7
|
|
|
use SocialiteProviders\Manager\Contracts\OAuth2\ProviderInterface; |
|
8
|
|
|
use SocialiteProviders\Manager\SocialiteWasCalled; |
|
9
|
|
|
use SocialiteProviders\Manager\ConfigTrait; |
|
10
|
|
|
use Laravel\Socialite\Two\AbstractProvider as BaseProvider; |
|
11
|
|
|
|
|
12
|
|
|
abstract class AbstractProvider extends BaseProvider implements ProviderInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use ConfigTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var array |
|
18
|
1 |
|
*/ |
|
19
|
|
|
protected $credentialsResponseBody; |
|
20
|
1 |
|
|
|
21
|
|
|
public static function serviceContainerKey($providerName) |
|
22
|
|
|
{ |
|
23
|
7 |
|
return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName; |
|
24
|
|
|
} |
|
25
|
7 |
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return \SocialiteProviders\Manager\OAuth2\User |
|
28
|
|
|
*/ |
|
29
|
|
|
public function user() |
|
30
|
|
|
{ |
|
31
|
|
|
if ($this->hasInvalidState()) { |
|
32
|
|
|
throw new InvalidStateException(); |
|
33
|
1 |
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
$response = $this->getAccessTokenResponse($this->getCode()); |
|
|
|
|
|
|
36
|
1 |
|
|
|
37
|
1 |
|
$user = $this->mapUserToObject($this->getUserByToken( |
|
38
|
1 |
|
$token = $this->parseAccessToken($response) |
|
39
|
|
|
)); |
|
40
|
1 |
|
|
|
41
|
|
|
$this->credentialsResponseBody = $response; |
|
42
|
|
|
|
|
43
|
|
|
if ($user instanceof User) { |
|
44
|
|
|
return $user->setAccessTokenResponseBody($this->credentialsResponseBody); |
|
45
|
|
|
} |
|
46
|
5 |
|
|
|
47
|
|
|
return $user->setToken($token) |
|
|
|
|
|
|
48
|
5 |
|
->setRefreshToken($this->parseRefreshToken($response)) |
|
49
|
2 |
|
->setExpiresIn($this->parseExpiresIn($response)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
3 |
|
/** |
|
53
|
3 |
|
* Get the access token from the token response body. |
|
54
|
3 |
|
* |
|
55
|
|
|
* @param string $body |
|
56
|
3 |
|
* |
|
57
|
|
|
* @return string |
|
58
|
3 |
|
*/ |
|
59
|
3 |
|
protected function parseAccessToken($body) |
|
60
|
|
|
{ |
|
61
|
|
|
return Arr::get($body, 'access_token'); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the refresh token from the token response body. |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $body |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function parseRefreshToken($body) |
|
72
|
3 |
|
{ |
|
73
|
|
|
return Arr::get($body, 'refresh_token'); |
|
|
|
|
|
|
74
|
3 |
|
} |
|
75
|
|
|
|
|
76
|
3 |
|
/** |
|
77
|
3 |
|
* Get the expires in from the token response body. |
|
78
|
3 |
|
* |
|
79
|
3 |
|
* @param string $body |
|
80
|
|
|
* |
|
81
|
3 |
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
3 |
|
protected function parseExpiresIn($body) |
|
84
|
|
|
{ |
|
85
|
|
|
return Arr::get($body, 'expires_in'); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.