Skip to content

Commit

Permalink
Get user profile from Steam API (fix #70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodge committed Jan 13, 2016
1 parent b345318 commit d414b9d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Yii2 EAuth Change Log
=====================

### dev (13.01.2016)
* Move response parsing from oauth to base service (fix #71)
* Move response parsing from oauth to base service (#71)
* Get user profile from Steam API (#70)

### 2.4.0 (03.01.2016)
* Fixed error param names for Facebook (#63)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ Add the following in your config:
'steam' => [
'class' => 'nodge\eauth\services\SteamOpenIDService',
//'realm' => '*.example.org', // your domain, can be with wildcard to authenticate on subdomains.
'apiKey' => '...', // Optional. You can get it here: https://steamcommunity.com/dev/apikey
],
'instagram' => [
// register your app here: https://instagram.com/developer/register/
Expand Down
32 changes: 25 additions & 7 deletions src/services/SteamOpenIDService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,34 @@ class SteamOpenIDService extends Service
protected $jsArguments = ['popup' => ['width' => 990, 'height' => 615]];

protected $url = 'http://steamcommunity.com/openid/';
protected $apiUrl = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/';

public $apiKey;

protected function fetchAttributes()
{
if (isset($this->attributes['id'])) {
$urlChunks = explode('/', $this->attributes['id']);
if ($count = count($urlChunks)) {
$name = $urlChunks[$count - 1];
$this->attributes['name'] = $name;
}
}
$chunks = explode('/', $this->attributes['id']);
$id = array_pop($chunks);

$this->attributes['name'] = $id;

if ($this->apiKey) {
$response = $this->makeRequest($this->apiUrl, [
'query' => [
'steamids' => $id,
'key' => $this->apiKey,
'format' => 'json'
]
]);

if (isset($response['response']['players'][0])) {
$profile = $response['response']['players'][0];

$this->attributes = array_merge($this->attributes, $profile);
$this->attributes['name'] = $profile['personaname'];
$this->attributes['url'] = $profile['profileurl'];
}
}
}

}

0 comments on commit d414b9d

Please sign in to comment.