Skip to content

Commit

Permalink
Merge pull request #37 from Sadzurami/fix/creation-webcookies
Browse files Browse the repository at this point in the history
fix creation webcookeis for `EAuthTokenPlatformType.WebBrowser`
  • Loading branch information
DoctorMcKay authored Jan 18, 2024
2 parents 698469c + bfd390c commit 005d05f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,12 @@ attempt if you already have a valid refresh token. Returns a Promise.
On failure, the Promise will be rejected. Depending on the nature of the failure, an EResult may or may not be available.

On success, the Promise will be resolved with an array of strings. Each string contains a cookie, e.g.
`'steamLoginSecure=blahblahblahblah'`.

`steamLoginSecure=blahblahblahblah`

or

`steamLoginSecure=blahblahblahblah; Path=/; Secure; HttpOnly; SameSite=None; Domain=steamcommunity.com`

Here's an example of how you can get new web cookies when you already have a valid refresh token:

Expand Down
32 changes: 4 additions & 28 deletions src/LoginSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,10 +865,11 @@ export default class LoginSession extends TypedEmitter<LoginSessionEvents> {
return reject(new Error('No steamLoginSecure cookie in result'));
}

resolve(result.headers['set-cookie'].map(c => c.split(';')[0].trim()));
let domain = new URL(url).host;
resolve(result.headers['set-cookie'].map(cookie => `${cookie}; Domain=${domain}`));
}));

let cookies = await promiseAny(transfers) as string[];
let cookies = await Promise.all(transfers) as string[];
if (!cookies.some((c) => c.includes('sessionid'))) {
cookies.push(`sessionid=${sessionId}`);
}
Expand Down Expand Up @@ -1016,29 +1017,4 @@ export default class LoginSession extends TypedEmitter<LoginSessionEvents> {
* @event
*/
static error = 'error';
}

/**
* @param {Promise[]} promises
* @returns {Promise}
*/
function promiseAny(promises): Promise<any> {
// for node <15 compat
return new Promise((resolve, reject) => {
let pendingPromises = promises.length;
let rejections = [];
promises.forEach((promise) => {
promise.then((result) => {
pendingPromises--;
resolve(result);
}).catch((err) => {
pendingPromises--;
rejections.push(err);

if (pendingPromises == 0) {
reject(rejections[0]);
}
});
});
});
}
}

0 comments on commit 005d05f

Please sign in to comment.