steamutils 1.4.25 → 1.4.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.js +7 -4
  2. package/package.json +1 -1
  3. package/utils.js +40 -0
package/index.js CHANGED
@@ -4946,10 +4946,9 @@ export default class SteamUser {
4946
4946
  }
4947
4947
  };
4948
4948
 
4949
- const isVerificationCodeSent = (html) => {
4949
+ const getHelpPageTitle = (html) => {
4950
4950
  const $ = cheerio.load(html);
4951
- const help_page_title = $("#forgot_login_code_form .help_page_title").text().trim();
4952
- return help_page_title.startsWith("A verification code was sent to phone number ending in");
4951
+ return $("#forgot_login_code_form .help_page_title").text().trim();
4953
4952
  };
4954
4953
 
4955
4954
  const { type, link: helpLink } = (await getHelpLink()) || {};
@@ -4985,7 +4984,9 @@ export default class SteamUser {
4985
4984
  };
4986
4985
  }
4987
4986
 
4988
- if (!isVerificationCodeSent(html)) {
4987
+ const help_page_title = getHelpPageTitle(html);
4988
+
4989
+ if (!help_page_title.startsWith("A verification code was sent to phone number ending in")) {
4989
4990
  const sendAccountRecoveryCodeResult = await this._httpRequest({
4990
4991
  url: `https://help.steampowered.com/en/wizard/AjaxSendAccountRecoveryCode`,
4991
4992
  headers: {
@@ -5006,12 +5007,14 @@ export default class SteamUser {
5006
5007
  return {
5007
5008
  success: !!sendAccountRecoveryCodeResult.data?.success,
5008
5009
  params,
5010
+ help_page_title,
5009
5011
  };
5010
5012
  }
5011
5013
 
5012
5014
  return {
5013
5015
  success: true,
5014
5016
  params,
5017
+ help_page_title,
5015
5018
  };
5016
5019
  }
5017
5020
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.4.25",
3
+ "version": "1.4.27",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",
package/utils.js CHANGED
@@ -166,3 +166,43 @@ export function decodeLoginQrUrl(qrUrl) {
166
166
 
167
167
  return { clientId: match[2], version: parseInt(match[1], 10) };
168
168
  }
169
+
170
+ export function decodeJwt(jwt) {
171
+ try {
172
+ const parts = jwt.split(".");
173
+ if (parts.length !== 3) {
174
+ console.err("decodeJwt Error", new Error("Invalid JWT"));
175
+ return;
176
+ }
177
+
178
+ const standardBase64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
179
+ return JSON.parse(Buffer.from(standardBase64, "base64").toString("utf8"));
180
+ } catch (e) {
181
+ console.err("decodeJwt Error", e);
182
+ }
183
+ }
184
+
185
+ export async function renewRefreshToken({ refreshToken, accessToken }) {
186
+ try {
187
+ const { aud } = decodeJwt(accessToken);
188
+ let platformType = EAuthTokenPlatformType.SteamClient;
189
+ if (aud.includes("mobile")) {
190
+ platformType = EAuthTokenPlatformType.MobileApp;
191
+ } else if (aud.includes("client")) {
192
+ platformType = EAuthTokenPlatformType.SteamClient;
193
+ } else if (aud.includes("web")) {
194
+ platformType = EAuthTokenPlatformType.WebBrowser;
195
+ }
196
+ const session = new LoginSession(platformType);
197
+ session.refreshToken = refreshToken;
198
+ await session.refreshAccessToken();
199
+ const cookie = (await session.getWebCookies())?.join?.(";");
200
+ return {
201
+ cookie,
202
+ accessToken: session.accessToken,
203
+ accessTokenDecoded: decodeJwt(session.accessToken),
204
+ };
205
+ } catch (e) {
206
+ console.error("renewRefreshToken Error", e);
207
+ }
208
+ }