steamutils 1.4.26 → 1.4.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils.js +40 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.4.26",
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
+ }