steamutils 1.4.26 → 1.4.28
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/utils.js +70 -0
package/package.json
CHANGED
package/utils.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { EAuthTokenPlatformType, LoginApprover } from "steam-session";
|
2
|
+
|
1
3
|
const isBrowser = typeof window !== "undefined";
|
2
4
|
|
3
5
|
export const sleep = (ms) => {
|
@@ -166,3 +168,71 @@ export function decodeLoginQrUrl(qrUrl) {
|
|
166
168
|
|
167
169
|
return { clientId: match[2], version: parseInt(match[1], 10) };
|
168
170
|
}
|
171
|
+
|
172
|
+
export function decodeJwt(jwt) {
|
173
|
+
try {
|
174
|
+
const parts = jwt.split(".");
|
175
|
+
if (parts.length !== 3) {
|
176
|
+
console.err("decodeJwt Error", new Error("Invalid JWT"));
|
177
|
+
return;
|
178
|
+
}
|
179
|
+
|
180
|
+
const standardBase64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
181
|
+
return JSON.parse(Buffer.from(standardBase64, "base64").toString("utf8"));
|
182
|
+
} catch (e) {
|
183
|
+
console.err("decodeJwt Error", e);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
export async function renewRefreshToken({ refreshToken, accessToken }) {
|
188
|
+
try {
|
189
|
+
const { aud } = decodeJwt(accessToken);
|
190
|
+
let platformType = EAuthTokenPlatformType.SteamClient;
|
191
|
+
if (aud.includes("mobile")) {
|
192
|
+
platformType = EAuthTokenPlatformType.MobileApp;
|
193
|
+
} else if (aud.includes("client")) {
|
194
|
+
platformType = EAuthTokenPlatformType.SteamClient;
|
195
|
+
} else if (aud.includes("web")) {
|
196
|
+
platformType = EAuthTokenPlatformType.WebBrowser;
|
197
|
+
}
|
198
|
+
const session = new LoginSession(platformType);
|
199
|
+
session.refreshToken = refreshToken;
|
200
|
+
await session.refreshAccessToken();
|
201
|
+
const cookie = (await session.getWebCookies())?.join?.(";");
|
202
|
+
return {
|
203
|
+
cookie,
|
204
|
+
accessToken: session.accessToken,
|
205
|
+
accessTokenDecoded: decodeJwt(session.accessToken),
|
206
|
+
};
|
207
|
+
} catch (e) {
|
208
|
+
console.error("renewRefreshToken Error", e);
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
export async function approveLogin({ steamId, url, sharedSecret, accessToken, shouldApprove }) {
|
213
|
+
try {
|
214
|
+
const approver = new LoginApprover(accessToken, sharedSecret, {});
|
215
|
+
const sessionInfo = await approver.getAuthSessionInfo(url);
|
216
|
+
sessionInfo.steamId = steamId;
|
217
|
+
|
218
|
+
if (typeof shouldApprove === "function" && !shouldApprove(sessionInfo)) {
|
219
|
+
return;
|
220
|
+
}
|
221
|
+
|
222
|
+
await approver.approveAuthSession({
|
223
|
+
qrChallengeUrl: url,
|
224
|
+
approve: true,
|
225
|
+
});
|
226
|
+
|
227
|
+
return {
|
228
|
+
steamId,
|
229
|
+
sessionInfo,
|
230
|
+
};
|
231
|
+
} catch (error) {
|
232
|
+
console.error("approveLogin Error", error);
|
233
|
+
return {
|
234
|
+
steamId,
|
235
|
+
error,
|
236
|
+
};
|
237
|
+
}
|
238
|
+
}
|