|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SocialConnect project |
|
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace SocialConnect\Auth\Provider; |
|
8
|
|
|
|
|
9
|
|
|
use SocialConnect\Auth\Provider\Exception\InvalidResponse; |
|
10
|
|
|
use SocialConnect\OpenID\AccessToken; |
|
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
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getIdentity(AccessToken $accessToken) |
|
44
|
|
|
{ |
|
45
|
|
|
preg_match( |
|
46
|
|
|
"/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/", |
|
47
|
|
|
$accessToken->getIdentity(), |
|
48
|
|
|
$matches |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
$userId = $matches[0]; |
|
52
|
|
|
|
|
53
|
|
|
$response = $this->service->getHttpClient()->request( |
|
54
|
|
|
$this->getBaseUri() . 'ISteamUser/GetPlayerSummaries/v0002/', |
|
55
|
|
|
[ |
|
56
|
|
|
'key' => $this->consumer->getKey(), |
|
57
|
|
|
'steamids' => $userId |
|
58
|
|
|
] |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
if (!$response->isSuccess()) { |
|
62
|
|
|
throw new InvalidResponse( |
|
63
|
|
|
'API response with error code', |
|
64
|
|
|
$response |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$result = $response->json(); |
|
69
|
|
|
if (!$result) { |
|
70
|
|
|
throw new InvalidResponse( |
|
71
|
|
|
'API response is not a valid JSON object', |
|
72
|
|
|
$response->getBody() |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$hydrator = new ObjectMap(array( |
|
77
|
|
|
'steamid' => 'id', |
|
78
|
|
|
'personaname' => 'username', |
|
79
|
|
|
'realname' => 'fullname' |
|
80
|
|
|
)); |
|
81
|
|
|
|
|
82
|
|
|
return $hydrator->hydrate(new User(), $result->response->players[0]); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|