A simple interface for authenticating users using Steam's OpenID provider
MIT License
This module provides a straightforward, secure, and non-opinionated way of authenticating Steam users in your application.
Steam provides some images you can use as buttons to direct users to Steam for authentication on their Steam Web API Documentation overview page.
Once you have an authenticated user's SteamID, you can retrieve their public profile information using the ISteamUser/GetPlayerSummaries Web API method. You will need an API key, which can be obtained from that same Steam Web API Documentation page linked above.
The module exports a SteamSignIn
class. Import it like so:
// CommonJS
const SteamSignIn = require('steam-signin');
// ES6 Modules
import SteamSignIn from 'steam-signin';
Construct a new instance of SteamSignIn
. You need to provide your realm, which is your domain and protocol (http or https).
let signIn = new SteamSignIn('https://example.com');
Call getUrl
to get the URL where you should redirect a user to authenticate. You need to supply a URL where the user
should be sent back to your site once they've signed in. Your return URL must match the realm you provided to the
constructor, or an Error will be thrown.
let authUrl = signIn.getUrl('https://example.com/auth/return');
At this point, you should redirect the authenticating user to that URL. Once they return to your site, call verifyLogin
to retrieve their authenticated SteamID.
let returnUrl = getReturnUrlSomehow();
// returnUrl must contain the URL the user landed at your site on, including all querystring parameters. How exactly you
// fetch this value will depend on the web framework you're using.
let steamId = await signIn.verifyLogin(returnUrl);
// If we make it here, the user has successfully authenticated. If their login data was bogus or reused, the verifyLogin()
// promise would reject, which you could catch with try/catch.
// steamId is a SteamID object (see https://www.npmjs.com/package/steamid)
console.log(`User successfully authenticated as ${steamId.getSteamID64()}`);
View a full usage example on GitHub here: steam-signin.js