npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

passport-steam-openid

v1.1.4

Published

Passport strategy for authenticating with steam openid without the use of 3rd party openid packages.

Downloads

482

Readme

passport-steam-openid

Passport strategy for authenticating with steam openid without the use of 3rd party openid packages, which have been proved to be source of many exploits of steam openid system, apparently by design. This package only relies on passport and axios.

Library is fully covered with tests, both unit and integration tests to make sure everything runs correctly.

API

Instantiate the SteamOpenIdStrategy as following:

new SteamOpenIdStrategy(options, verify)

Options object has the following properties:

  • returnURL - URL to which steam will redirect user after authentication
  • profile - If set to true, it will fetch user profile from steam api, otherwise only steamid will be returned
  • apiKey - Steam api key, required if options.profile is set to true
  • maxNonceTimeDelay - Optional, in seconds, time between creation and verification of nonce date, if not set no verification occurs.

Second parameter of SteamOpenIdStrategy is a callback function used for verifying logged in user, with the following parameters:

  • req - Express request object
  • steamid - Steam id of the authenticated user
  • profile - Full profile from GetPlayerSummaries api, if options.profile is set to true, otherwise only steamid
  • done - Passport callback function

Profile if options.profile is set to true:

export type SteamOpenIdUserProfile = {
  steamid: string;
  communityvisibilitystate: number;
  profilestate: number;
  personaname: string;
  commentpermission: number;
  profileurl: string;
  avatar: string;
  avatarmedium: string;
  avatarfull: string;
  avatarhash: string;
  lastlogoff: number;
  personastate: number;
  realname: string;
  primaryclanid: string;
  timecreated: number;
  personastateflags: number;
  loccountrycode: string;
  locstatecode: string;
};

Other it is just:

export type SteamOpenIdUser = {
  steamid: string;
};

Usage

import { SteamOpenIdStrategy } from 'passport-steam-openid';

passport.use(
    new SteamOpenIdStrategy({
        returnURL: 'http://localhost:3000/auth/steam',
        profile: true,
        apiKey: '<insert steam api key>', // No need for api key, if profile is set to false
        maxNonceTimeDelay: 30 // Optional, in seconds, time between creation and verification of nonce date
    }, (
        req: Request, 
        identifier: string, 
        profile: SteamOpenIdUserProfile, // if profile is false, then it's only { steamid }, otherwise full profile from GetPlayerSummaries api
        done: VerifyCallback
    ) => {
        // Optional callback called only when successful authentication occurs
        // You can save the user to database here.
    })
)

app.get('/auth/steam', passport.authenticate('steam-openid'), (req, res) => {
    // When requested first by user,
    // they will get redirected to steam and this function is never called.
    // Second time, after user is authenticated, this function is called.
})

Error handling

app.use(
  (err: Error, req: Request, res: Response): void => {
    if (err instanceof SteamOpenIdError) {
      switch (err.code) {
        case SteamOpenIdErrorType.InvalidQuery:
            // Supplied querystring was invalid
        case SteamOpenIdErrorType.Unauthorized:
            // Steam rejected this authentication request
        case SteamOpenIdErrorType.InvalidSteamId:
            // Steam profile doesn't exist
        case SteamOpenIdErrorType.NonceExpired:
            // Nonce has expired, only if `options.maxNonceTimeDelay` is set
      }
    }
    // ...
  },
);

Sample

Visit sample directory for more elaborate usage example.

Instalation

Install using npm:

npm install passport-steam-openid

Library's API has been unchanged and stable for some time now. It will not change unless a breaking change is issued by steam (very unlikely).

License

This library is released under MIT license.