Skip to content

Commit 9834f0c

Browse files
committed
:octocat: +Steam UserInfo
1 parent d84ce65 commit 9834f0c

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

.config/.env_example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ SPOTIFY_CALLBACK_URL=
216216
STEAMOPENID_KEY=
217217
STEAMOPENID_SECRET=
218218
STEAMOPENID_CALLBACK_URL=
219+
#STEAMOPENID_TESTUSER=
219220

220221
# https://dashboard.stripe.com/account/apikeys
221222
STRIPE_KEY=

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Note: replace `dev-main` with a [version constraint](https://getcomposer.org/doc
133133
| [Slack](https://api.slack.com) | [link](https://api.slack.com/apps) | [link](https://slack.com/apps/manage) | 2 ||| | | | |
134134
| [SoundCloud](https://developers.soundcloud.com/) | [link](https://soundcloud.com/you/apps) | [link](https://soundcloud.com/settings/connections) | 2 || | ||| |
135135
| [Spotify](https://developer.spotify.com/documentation/web-api/) | [link](https://developer.spotify.com/dashboard) | [link](https://www.spotify.com/account/apps/) | 2 ||| ||| |
136-
| [SteamOpenID](https://developer.valvesoftware.com/wiki/Steam_Web_API) | [link](https://steamcommunity.com/dev/apikey) | | - | | | | | | |
136+
| [SteamOpenID](https://developer.valvesoftware.com/wiki/Steam_Web_API) | [link](https://steamcommunity.com/dev/apikey) | | - | | | | | | |
137137
| [Stripe](https://stripe.com/docs/api) | [link](https://dashboard.stripe.com/apikeys) | [link](https://dashboard.stripe.com/account/applications) | 2 ||| | |||
138138
| [Tumblr](https://www.tumblr.com/docs/en/api/v2) | [link](https://www.tumblr.com/oauth/apps) | [link](https://www.tumblr.com/settings/apps) | 1 || | | | | |
139139
| [Tumblr2](https://www.tumblr.com/docs/en/api/v2) | [link](https://www.tumblr.com/oauth/apps) | [link](https://www.tumblr.com/settings/apps) | 2 ||| ||| |

docs/Basics/Overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fully [PSR-7](https://www.php-fig.org/psr/psr-7/)/[PSR-17](https://www.php-fig.o
7272
| [Slack](https://api.slack.com) | [link](https://api.slack.com/apps) | [link](https://slack.com/apps/manage) | 2 ||| | | | |
7373
| [SoundCloud](https://developers.soundcloud.com/) | [link](https://soundcloud.com/you/apps) | [link](https://soundcloud.com/settings/connections) | 2 || | ||| |
7474
| [Spotify](https://developer.spotify.com/documentation/web-api/) | [link](https://developer.spotify.com/dashboard) | [link](https://www.spotify.com/account/apps/) | 2 ||| ||| |
75-
| [SteamOpenID](https://developer.valvesoftware.com/wiki/Steam_Web_API) | [link](https://steamcommunity.com/dev/apikey) | | - | | | | | | |
75+
| [SteamOpenID](https://developer.valvesoftware.com/wiki/Steam_Web_API) | [link](https://steamcommunity.com/dev/apikey) | | - | | | | | | |
7676
| [Stripe](https://stripe.com/docs/api) | [link](https://dashboard.stripe.com/apikeys) | [link](https://dashboard.stripe.com/account/applications) | 2 ||| | |||
7777
| [Tumblr](https://www.tumblr.com/docs/en/api/v2) | [link](https://www.tumblr.com/oauth/apps) | [link](https://www.tumblr.com/settings/apps) | 1 || | | | | |
7878
| [Tumblr2](https://www.tumblr.com/docs/en/api/v2) | [link](https://www.tumblr.com/oauth/apps) | [link](https://www.tumblr.com/settings/apps) | 2 ||| ||| |

src/Providers/SteamOpenID.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
namespace chillerlan\OAuth\Providers;
1313

1414
use chillerlan\HTTP\Utils\QueryUtil;
15-
use chillerlan\OAuth\Core\{AccessToken, OAuthProvider};
15+
use chillerlan\OAuth\Core\{AccessToken, AuthenticatedUser, OAuthProvider, UserInfo};
16+
use chillerlan\HTTP\Utils\UriUtil;
1617
use Psr\Http\Message\{RequestInterface, ResponseInterface, UriInterface};
1718
use function explode, intval, preg_replace;
1819

@@ -23,7 +24,7 @@
2324
* @see https://partner.steamgames.com/doc/webapi_overview
2425
* @see https://steamwebapi.azurewebsites.net/
2526
*/
26-
class SteamOpenID extends OAuthProvider{
27+
class SteamOpenID extends OAuthProvider implements UserInfo{
2728

2829
protected string $authorizationURL = 'https://steamcommunity.com/openid/login';
2930
protected string $accessTokenURL = 'https://steamcommunity.com/openid/login';
@@ -114,17 +115,34 @@ protected function parseTokenResponse(ResponseInterface $response):AccessToken{
114115
*
115116
*/
116117
public function getRequestAuthorization(RequestInterface $request, AccessToken|null $token = null):RequestInterface{
117-
$token ??= $this->storage->getAccessToken($this->name);
118+
$uri = UriUtil::withQueryValue($request->getUri(), 'key', $this->options->secret);
118119

119-
$uri = (string)$request->getUri();
120-
$params = ['key' => $this->options->secret];
120+
return $request->withUri($uri);
121+
}
122+
123+
/**
124+
* @inheritDoc
125+
* @codeCoverageIgnore
126+
*/
127+
public function me():AuthenticatedUser{
128+
$token = $this->storage->getAccessToken($this->name);
129+
$json = $this->getMeResponseData('/ISteamUser/GetPlayerSummaries/v0002/', ['steamids' => $token->accessToken]);
121130

122-
// the steamid parameter does not necessarily specify the current user, so add it only when it's not already set
123-
if(!str_contains($uri, 'steamid=')){
124-
$params['steamid']= $token->accessToken;
131+
if(!isset($json['response']['players'][0])){
132+
throw new ProviderException('invalid response');
125133
}
126134

127-
return $request->withUri($this->uriFactory->createUri(QueryUtil::merge($uri, $params)));
135+
$data = $json['response']['players'][0];
136+
137+
$userdata = [
138+
'data' => $data,
139+
'avatar' => $data['avatarfull'],
140+
'displayName' => $data['personaname'],
141+
'id' => $data['steamid'],
142+
'url' => $data['profileurl'],
143+
];
144+
145+
return new AuthenticatedUser($userdata);
128146
}
129147

130148
}

tests/Providers/Live/SteamOpenIDAPITest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace chillerlan\OAuthTest\Providers\Live;
1313

14+
use chillerlan\OAuth\Core\AuthenticatedUser;
1415
use chillerlan\OAuth\Providers\SteamOpenID;
1516
use PHPUnit\Framework\Attributes\Group;
1617

@@ -42,4 +43,9 @@ public function testUnauthorizedAccessException():void{
4243
$this::markTestSkipped('N/A');
4344
}
4445

46+
protected function assertMeResponse(AuthenticatedUser $user):void{
47+
var_dump($user);
48+
$this::assertSame((int)$this->TEST_USER, $user->id);
49+
}
50+
4551
}

0 commit comments

Comments
 (0)