DoctorMcKay / node-steam-user

Allows interaction with the Steam network via the Steam client protocol
https://dev.doctormckay.com/forum/7-node-steam-user/
MIT License
888 stars 157 forks source link

authorizeLocalSharingDevice authorizing incorrect local_device_token #341

Open andandy12 opened 3 years ago

andandy12 commented 3 years ago

Describe the bug

When attempting to authorize my local device it seems to be reporting the incorrect token for the device...

I was attempting to authorize my computer for an alt account so I could automate sharing games with alts... The local client running from C: drive never would pick up on the fact that the account had already been authorized. I can confirm that the main account with the games, had the alt as a borrower and the os.hostname under the device name list; however, it still did not work. I thought maybe it had not been updated in the client so I attempted to borrow the game by pressing the borrow button. This added another os.hostname to the device list in my mains account family sharing details.

The next step I took was to getAuthorizedSharingDevices() this had dumped a device with the proper token matching up with the one in config.vdf and another matched nothing on my disk.

At first I thought maybe I need to use the same sentry file for the account so I went into config.vdf and grabbed the sentry file currently used and setSentry(buffer) in an attempt to have the proper device token apear. This did not work for me.

var sentryfile = fs.readFileSync("C:\\Program Files (x86)\\Steam\\config\\config.vdf").toString();
sentryfile = VDF.parse(sentryfile).InstallConfigStore.Software.Valve.steam.SentryFile;
const sentrybuffer = fs.readFileSync(sentryfile);
console.log(sentrybuffer);
client.setSentry(sentrybuffer);

I then attempted to modify the current authorizeLocalSharingDevice() function and created this function in the image

/**
 * Authorize remote device for library sharing.
 * @param {string} deviceName
 * @param {function} [callback]
 * @returns {Promise}
 */
SteamUser.prototype.authorizeRemoteSharingDevice = function(deviceName,deviceToken, callback) {
    return StdLib.Promises.timeoutCallbackPromise(5000, null, callback, true, (resolve, reject) => {
        if (!deviceName) {
            return reject(new Error('The \'deviceName\' argument is required.'));
        }
        if (!deviceToken) {
            return reject(new Error('The \'deviceToken\' argument is required.'));
        }

        this._send(SteamUser.EMsg.ClientAuthorizeLocalDeviceRequest, {
            device_description: deviceName,
            owner_account_id: this.steamID.accountid,
            local_device_token: deviceToken
        }, (body) => {
            let err = Helpers.eresultError(body.eresult);
            return err ? reject(err) : resolve({deviceToken: body.authed_device_token});
        });
    });
};

It is extremely similar to the original function but with an added local_device_token: deviceToken in the request. I added this to the request, because in this post by DoctorMcKay, it appears one should be able to send the request with a custom token. This however had not matched any device that was being authorized, nor what I had passed into the custom function. An image of what was happening is here. At this point, I thought my implementation was bad and that you can not pass a custom token.

My question is, how should I use authorizeLocalSharingDevice() within my environment so that it will capture the proper device token.

LelouBil commented 1 year ago

Did it work in the end ?

LelouBil commented 1 year ago

Okay, for anyone stumbling here: To be valid, you need to match the "machine_id" !!! The sentry file is useless !

I did experiments with authorizing a computer remotely and manually writing the device_token to the steam config file. It did not work with the sentry file. However, when I also grabbed the "machine_id" of the remote computer, the token worked when added to the config ! Removing the usage of the sentry file works too. @DoctorMcKay you might want to be aware of this, since the wiki talks about the sentry file instead, but it is (now ?) wrong.

pjy612 commented 6 months ago

machine_id

how to get machine_id same with steam ? @LelouBil