1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SocialConnect project |
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace SocialConnect\OpenID\Provider; |
8
|
|
|
|
9
|
|
|
use SocialConnect\Provider\AccessTokenInterface; |
10
|
|
|
use SocialConnect\Provider\Exception\InvalidResponse; |
11
|
|
|
use SocialConnect\Common\Entity\User; |
12
|
|
|
use SocialConnect\Common\Hydrator\ObjectMap; |
13
|
|
|
|
14
|
|
|
class Steam extends \SocialConnect\OpenID\AbstractProvider |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
*/ |
19
|
|
|
public function getOpenIdUrl() |
20
|
|
|
{ |
21
|
|
|
return 'http://steamcommunity.com/openid/id'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function getBaseUri() |
28
|
|
|
{ |
29
|
|
|
return 'http://api.steampowered.com/'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function getName() |
36
|
|
|
{ |
37
|
|
|
return 'steam'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $identity |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
protected function parseUserIdFromIdentity($identity) |
45
|
|
|
{ |
46
|
|
|
preg_match( |
47
|
|
|
'/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/', |
48
|
|
|
$identity, |
49
|
|
|
$matches |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
return $matches[1]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function getIdentity(AccessTokenInterface $accessToken) |
60
|
|
|
{ |
61
|
|
|
$response = $this->httpClient->request( |
62
|
|
|
$this->getBaseUri() . 'ISteamUser/GetPlayerSummaries/v0002/', |
63
|
|
|
[ |
64
|
|
|
'key' => $this->consumer->getKey(), |
65
|
|
|
'steamids' => $accessToken->getUserId() |
66
|
|
|
] |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
if (!$response->isSuccess()) { |
70
|
|
|
throw new InvalidResponse( |
71
|
|
|
'API response with error code', |
72
|
|
|
$response |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$result = $response->json(); |
77
|
|
|
if (!$result) { |
78
|
|
|
throw new InvalidResponse( |
79
|
|
|
'API response is not a valid JSON object', |
80
|
|
|
$response->getBody() |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$hydrator = new ObjectMap( |
85
|
|
|
[ |
86
|
|
|
'steamid' => 'id', |
87
|
|
|
'personaname' => 'username', |
88
|
|
|
'realname' => 'fullname' |
89
|
|
|
] |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
return $hydrator->hydrate(new User(), $result->response->players[0]); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|