1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SocialConnect project |
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace SocialConnect\Auth\Provider\OpenID; |
8
|
|
|
|
9
|
|
|
use SocialConnect\Auth\Exception\InvalidAccessToken; |
10
|
|
|
use SocialConnect\Auth\Provider\AbstractBaseProvider; |
11
|
|
|
use SocialConnect\Common\Entity\User; |
12
|
|
|
use SocialConnect\Common\Http\Client\Client; |
13
|
|
|
|
14
|
|
|
abstract class AbstractProvider extends AbstractBaseProvider |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @return string |
18
|
|
|
*/ |
19
|
|
|
abstract public function getOpenIdUrl(); |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
protected $version; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $loginEntrypoint; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param bool $immediate |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
protected function makeAuthUrlV2($immediate) |
36
|
|
|
{ |
37
|
|
|
$params = array( |
38
|
|
|
'openid.ns' => 'http://specs.openid.net/auth/2.0', |
39
|
|
|
'openid.mode' => $immediate ? 'checkid_immediate' : 'checkid_setup', |
40
|
|
|
'openid.return_to' => $this->getRedirectUrl(), |
41
|
|
|
'openid.realm' => $this->getRedirectUrl() |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$params['openid.ns.sreg'] = 'http://openid.net/extensions/sreg/1.1'; |
45
|
|
|
$params['openid.identity'] = $params['openid.claimed_id'] = 'http://specs.openid.net/auth/2.0/identifier_select'; |
46
|
|
|
|
47
|
|
|
return $this->loginEntrypoint . '?' . http_build_query($params, '', '&'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $url |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
protected function discover($url) |
55
|
|
|
{ |
56
|
|
|
$response = $this->service->getHttpClient()->request( |
|
|
|
|
57
|
|
|
$url, |
58
|
|
|
[], |
59
|
|
|
Client::GET, |
60
|
|
|
[ |
61
|
|
|
'Content-Type' => 'application/json' |
62
|
|
|
] |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$this->version = 2; |
66
|
|
|
$this->loginEntrypoint = 'https://steamcommunity.com/openid/login'; |
67
|
|
|
|
68
|
|
|
return $this->getOpenIdUrl(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function makeAuthUrl() |
72
|
|
|
{ |
73
|
|
|
$this->discover($this->getOpenIdUrl()); |
74
|
|
|
|
75
|
|
|
return $this->makeAuthUrlV2(false); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @link http://openid.net/specs/openid-authentication-2_0.html#verification |
80
|
|
|
* |
81
|
|
|
* @param $requestParameters |
82
|
|
|
* @return AccessToken |
83
|
|
|
* @throws \SocialConnect\Auth\Exception\InvalidAccessToken |
84
|
|
|
*/ |
85
|
|
|
public function getAccessTokenByRequestParameters($requestParameters) |
86
|
|
|
{ |
87
|
|
|
$params = array( |
88
|
|
|
'openid.assoc_handle' => $requestParameters['openid_assoc_handle'], |
89
|
|
|
'openid.signed' => $requestParameters['openid_signed'], |
90
|
|
|
'openid.sig' => $requestParameters['openid_sig'], |
91
|
|
|
'openid.ns' => $requestParameters['openid_ns'], |
92
|
|
|
'openid.op_endpoint' => $requestParameters['openid_op_endpoint'], |
93
|
|
|
'openid.claimed_id' => $requestParameters['openid_claimed_id'], |
94
|
|
|
'openid.identity' => $requestParameters['openid_identity'], |
95
|
|
|
'openid.return_to' => $this->getRedirectUrl(), |
96
|
|
|
'openid.response_nonce' => $requestParameters['openid_response_nonce'], |
97
|
|
|
'openid.mode' => 'check_authentication' |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
if (isset($requestParameters['openid_claimed_id'])) { |
101
|
|
|
$claimedId = $requestParameters['openid_claimed_id']; |
102
|
|
|
} else { |
103
|
|
|
$claimedId = $requestParameters['openid_identity']; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$server = $this->discover($claimedId); |
|
|
|
|
107
|
|
|
|
108
|
|
|
$response = $this->service->getHttpClient()->request( |
109
|
|
|
'https://steamcommunity.com/openid/login', |
110
|
|
|
$params, |
111
|
|
|
Client::POST |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
if (preg_match('/is_valid\s*:\s*true/i', $response->getBody())) { |
115
|
|
|
return new AccessToken($requestParameters['openid_identity']); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
throw new InvalidAccessToken; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.