bearsys / steam
Package combining several Steam-related libraries into one wrapped and easy-to-use package.
Requires
- ehesp/steam-login: ^1.1
- koraktor/steam-condenser: ^1.3
- xpaw/steamid: ^1.0
- zyberspace/steam-web-api-client: ^0.5.0
Requires (Dev)
- nette/application: ^2.4
- nette/di: ^2.4
- nette/tester: ^2.0
Suggests
- nette/application: Required for Nette framework login component. You should already have this if you want to use the login component.
- nette/di: Required for Nette framework extension. You should already have this if you want to use the extension.
This package is not auto-updated.
Last update: 2025-03-27 18:10:37 UTC
README
This package combines several useful PHP libraries for working with Steam IDs, Steam Web API and Steam oAuth.
Can be used standalone or as Nette framework extension.
Package currently includes these libraries:
Ehesp/Steam-Login
- used for Nette login componentxPaw/SteamID
- used for conversions of Steam IDszyberspace/php-steam-web-api-client
- used for querying Steam Web API
Installation
composer require bearsys/steam
Usage
Note that Valve limits requests to this API (if you don't have publisher's key). There should be daily limit of 100,000 requests. That is 69 requests per minute. But you could probably make all 100,000 requests at once, although it is not recommended.
Standalone
Create instance of BearSys\Steam\SteamWrapper
, provide you Steam Web API user key as constructor parameter.
You can then work with this wrapper as you wish.
Example:
$apiKey = 'KEY_GOES_HERE'; // Your API key, matches regex ^[0-9A-F]{32}$ $wrapper = new BearSys\Steam\SteamWrapper($apiKey); $user = $wrapper->getUser('hitzor'); // you could use any form of Steam ID or vanity URL $user->getInfo(); // returns info about selected user $game = $wrapper->getGame(730); // 730 is CS:GO's AppID $game->getActivePlayersCount(); // returns how many players are currently playing
Nette framework
Register extension in your config and set Steam Web API key.
extensions: steam: BearSys\Steam\Bridges\NetteDI\SteamExtension steam: apiKey: # your Steam Web API key goes here
You can request SteamWrapper after that in every class that is created using Nette DI.
Login component
Extension will register login factory. Inject it into your presenter (or any other component) and use it's setup method to set callbacks.
/** @var BearSys\Steam\Bridges\NetteApplication\SteamLoginFactory @inject */ public $loginFactory; // you could use any suitable injection method, this is just the example public function createComponentSteamLogin() { $successCallback = function (string $steamId, bool $registered) { if ($registered) $this->redirect('this'); else $this->redirect('User:signUpSteam', $steamId); }; $failureCallback = function (\Exception $e) { // log $e }; return $this->loginFactory->setup( function (SteamLogin $login) use ($successCallback, $failureCallback) { $this->steamAuthenticator->login($login, $successCallback, $failureCallback); } ); }
Then you need to handle login inside your own authenticator. You could also do that inside your callback and then just call Nette\Security\User::login()
method with Nette\Security\IIdentity
instance, but we recommend to don't do that.
use Ehesp\SteamLogin\SteamLogin; class SteamAuthenticator extends AbstractAuthenticator { public function login(SteamLogin $login, callable $success, callable $failure) { try { $steamId = $login->validate(); // if this failed, it will throw an exception /* * Your custom logic goes here. * * You will probably want to check, if Steam ID is in database. * If it is, then just login associated user. * If it isn't, then create user and redirect him to sign-up page * with pre-filled username from Steam (obtainable using SteamWrapper). */ $success($steamId, $registered); } catch (\Exception $e) { // Login attempt failed $failure($e); } } }
At last, create link to component handle and style it however you want.
<a href="{link steamLogin-steamLogin!}">Steam login</a>
Future plans
- Tests (ASAP)
- Integrate
koraktor/steam-condenser-php
- Add support for Symfony, Laravel and other frameworks (pull-requests are welcomed)
- Consider supporting Steamworks publisher's API endpoints