JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 86
  • Score
    100M100P100Q76857F
  • License MIT

A modern passport strategy for steam with hopefully no bugs!

Package Exports

  • modern-passport-steam
  • modern-passport-steam/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (modern-passport-steam) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Modern Steam OpenID strategy for Passport

A modern Passport strategy for authenticating with Steam using OpenID 2.0. Inspired by the original passport-steam strategy, and DoctorMcKay's node-steam-signin library.

Installation

$ npm install --save modern-passport-steam

Contents

Options

This strategy takes an options object with the following properties:

  • returnUrl - The URL to which Steam will redirect the user after authentication. This should be the URL of the route that calls passport.authenticate('steam').
  • realm - The URL to which Steam will redirect the user after authentication. This should be the root URL of your website.
  • fetchSteamLevel - Whether or not to fetch the user's Steam level. Defaults to true if an API key is provided.
  • fetchUserProfile - Whether or not to fetch the user's profile. Defaults to true if an API key is provided.
  • apiKey - A Steam API key to use for fetching the user's Steam level and profile. Can be a string or a function that returns a string. Can be async if you need to fetch the key from a remote service!

Example options object:

{
    returnUrl: 'http://localhost:3000/login/return',
    realm: 'http://localhost:3000/',
    fetchSteamLevel: true, // Defaults to true if an API key is provided
    fetchUserProfile: true, // Defaults to true if an API key is provided
    apiKey: () => {
        // You should return your Steam API key here
        // For security, you should use environment variables or a secure key management service
        // Can be a string or a function that returns a string
        // Can be async if you need to fetch the key from a remote service!
        return 'MY_STEAM_API_KEY';
    }
}

Usage

Require Strategy

const SteamStrategy = require('modern-passport-steam');

Configure Strategy

If you want to fetch the user's Steam level and profile, you will need to provide a Steam API key. You can get one here. If you do not pass an api key, the first parameter passed to the verify callback will be the SteamID object, as you can see in the examples below.

With Profile Fetching:

passport.use(new SteamStrategy({
    returnUrl: 'http://localhost:3000/login/return',
    realm: 'http://localhost:3000/',
    fetchSteamLevel: true,
    fetchUserProfile: true,
    apiKey: () => {
        // You should return your Steam API key here
        // For security, you should use environment variables or a secure key management service
        // Can be a string or a function that returns a string
        // Can be async if you need to fetch the key from a remote service!
        return 'MY_STEAM_API_KEY';
    }
}, (user, done) => {
    // Here you would look up the user in your database using the SteamID
    // For this example, we're just passing the full user object back

    done(null, user);
}));

Example user object if you pass an API key:

{
  SteamID: SteamID { universe: 1, type: 1, instance: 1, accountid: 893472231 },
  profile: {
    steamid: '76561198853737959',
    communityvisibilitystate: 3,
    profilestate: 1,
    personaname: 'sampli',
    commentpermission: 1,
    profileurl: 'https://steamcommunity.com/id/shamp/',
    avatar: 'https://avatars.steamstatic.com/979e4a6baa364403e1dc268a52034162044ae391.jpg',
    avatarmedium: 'https://avatars.steamstatic.com/979e4a6baa364403e1dc268a52034162044ae391_medium.jpg',
    avatarfull: 'https://avatars.steamstatic.com/979e4a6baa364403e1dc268a52034162044ae391_full.jpg',
    avatarhash: '979e4a6baa364403e1dc268a52034162044ae391',
    lastlogoff: 1716699862,
    personastate: 0,
    primaryclanid: '103582791429521408',
    timecreated: 1534350460,
    personastateflags: 0
  },
  level: 52
}

Without Profile Fetching:

passport.use(new SteamStrategy({
    returnUrl: 'http://localhost:3000/login/return',
    realm: 'http://localhost:3000/'
}, (SteamID, done) => {
    // Here you would look up the user in your database using the SteamID
    // For this example, we're just passing the SteamID64 back as the user id
    const user = {
        id: SteamID.getSteamID64()
    };

    done(null, user);
}));

Authenticate Requests

Use passport.authenticate(), specifying the 'steam' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/login', passport.authenticate('steam'));

app.get('/login/return', passport.authenticate('steam', {
    failureRedirect: '/login'
}), (req, res) => {
    // Successful authentication, redirect home.
    res.redirect('/');
});

Examples

There is a basic example using express in the examples folder.

License

The MIT License