Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix creation webcookeis for EAuthTokenPlatformType.WebBrowser #37

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]);
}
});
});
});
}
}