Login into a website with steam login using nodejs

10,072

Solution 1

To answer your question, yes. There is a way of doing this.

The first thing you'll need to do is get a steam api key which you can do by heading over here. Then as steam says:

Just download an OpenID library for your language and platform of choice and use http://steamcommunity.com/openid as the provider. The returned Claimed ID will contain the user's 64-bit SteamID. The Claimed ID format is: http://steamcommunity.com/openid/id/

If you're set on using Node.JS I suggest checking out node-jsonwebtoken or passport-openidconnect. If you choose to go with passport, someone has already developed a "strategy" for including steam. Check that out here.

Solution 2

I have the same issue, i dont know if it helps you, but i wrote some methods to get user steamID, then u can use it to get user info with this method. I did it only having info how to do it with PHP - thats why i wanted to rewrite it on js.

1) method to build link

const http_build_query = (obj) => {
    let str = ""

    for (const key in obj) {
        const value = obj[key];
        str += `${key}=${value}&`;
    }

    return str;
}

2) method which returns you link where you shoud go to login with steam (you also can use in in )

const genUrl = (urlToReturnTo) => {
    const params = {
        'openid.ns'         : 'http://specs.openid.net/auth/2.0',
        'openid.mode'       : 'checkid_setup',
        'openid.return_to'  :  urlToReturnTo,
        'openid.realm'      : 'http://localhost:8080',
        'openid.identity'   : 'http://specs.openid.net/auth/2.0/identifier_select',
        'openid.claimed_id' : 'http://specs.openid.net/auth/2.0/identifier_select',
    };

    const url = `${STEAM_LOGIN}?${http_build_query(params)}`
    return url;
};

Also in method genUrl you need to pass as a param url where you want to be redirected after login. If login is successful you will be redirected to your url and will have some params in url it will look like "http://yoururl?here_is_params" and you need to get some how [here_is_params] from url i used this:

const search = location.search.substring(1);
const urlObj = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')

So after that you will have an object with query params

3) Now all you need its to get steamID from this object:

const getUserId = (response) =>
{
    const str = response["openid.claimed_id"];
    const res = decodeURIComponent(str)
    const propsArr = res.split("\/");
    console.log(propsArr);

    return propsArr[propsArr.length-1];
}


const userId = getUserId(urlObj)

4) Now you have userId and all you need its to send request with fetch or axios. it will return you an JSON OBJ with user data

 http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={apiKey}&steamids=${userId} 
Share:
10,072
Hel Oe
Author by

Hel Oe

Updated on August 21, 2022

Comments

  • Hel Oe
    Hel Oe over 1 year

    I am trying to log in to a website like for this example csgolounge which requires the steam login authentication using nodejs.

    Even thought I have tried a few things none of them came even close to working, so there is no point of me including the code here.

    I was wondering if there is any way of doing this.

    EDIT: I think I write my question incorrectly as I want the node application to login to csgolounge using steam and NOT have a website that is 'like' csgolounge with the login option.

  • Hel Oe
    Hel Oe about 8 years
    I am wondering if you understood my question correctly as I think I wrote it completly wrong. I don't want a website that has a feature 'like' csgolounge which is the steam login. I want my node application to log on to the website csgolounge which uses steam auth. I am not sure if you understood me correctly because I have used the steam api before, but I don't know if there is a way of me logging in to the steam with openid and returning to csgolounge logged in?
  • Sergio
    Sergio almost 3 years
    What if a user modify the query string and set the claimed_id to another steam ID?
  • madfluger
    madfluger almost 3 years
    I don’t think that I understand it correct, but in any case if you modify url, you receive different response. If I didn’t understand it right write your question more expanded