steamutils 1.4.27 → 1.4.29

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils.js +30 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.4.27",
3
+ "version": "1.4.29",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",
package/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { EAuthTokenPlatformType, LoginApprover, LoginSession } from "steam-session";
2
+
1
3
  const isBrowser = typeof window !== "undefined";
2
4
 
3
5
  export const sleep = (ms) => {
@@ -206,3 +208,31 @@ export async function renewRefreshToken({ refreshToken, accessToken }) {
206
208
  console.error("renewRefreshToken Error", e);
207
209
  }
208
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
+ }