steamutils 1.4.26 → 1.4.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils.js +40 -0
package/package.json
CHANGED
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
|
+
}
|