@ianlucas/remix-auth-steam 4.1.0 → 5.0.1

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/dist/index.d.ts CHANGED
@@ -1,19 +1,23 @@
1
- import { SessionStorage } from "@remix-run/server-runtime";
2
- import { AuthenticateOptions, Strategy, StrategyVerifyCallback } from "remix-auth";
3
- import { UserSummary } from "steamapi";
4
- export interface SteamStrategyOptions {
5
- apiKey: string;
6
- onError?: (error: unknown) => void;
7
- realm?: string;
8
- returnURL: string;
1
+ import { Strategy } from "remix-auth/strategy";
2
+ import { type UserSummary } from "steamapi";
3
+ declare namespace SteamStrategy {
4
+ interface Options {
5
+ apiKey: string;
6
+ onError?: (error: unknown) => void;
7
+ realm?: string;
8
+ returnURL: string;
9
+ }
10
+ type VerifyOptions = {
11
+ request: Request;
12
+ user: UserSummary;
13
+ };
9
14
  }
10
- export type SteamStrategyVerifyParams = {
11
- request: Request;
12
- user: UserSummary;
13
- };
14
- export declare class SteamStrategy<User> extends Strategy<User, SteamStrategyVerifyParams> {
15
+ export declare class SteamStrategy<User> extends Strategy<User, SteamStrategy.VerifyOptions> {
15
16
  private options;
16
17
  name: string;
17
- constructor(options: SteamStrategyOptions | ((request: Request) => Promise<SteamStrategyOptions>), verify: StrategyVerifyCallback<User, SteamStrategyVerifyParams>);
18
- authenticate(request: Request, sessionStorage: SessionStorage, options: AuthenticateOptions): Promise<User>;
18
+ constructor(options: SteamStrategy.Options | ((request: Request) => Promise<SteamStrategy.Options>), verify: Strategy.VerifyFunction<User, SteamStrategy.VerifyOptions>);
19
+ private authenticateToSteam;
20
+ private verifySteamAssertion;
21
+ authenticate(request: Request): Promise<User>;
19
22
  }
23
+ export {};
package/dist/index.js CHANGED
@@ -2,46 +2,42 @@
2
2
  * Copyright (c) Ian Lucas. All rights reserved.
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { redirect } from "@remix-run/server-runtime";
6
5
  import OpenID from "openid";
7
- import { Strategy } from "remix-auth";
8
- import SteamAPI from "steamapi";
9
- function authenticateToSteam(relyingParty) {
10
- return new Promise((resolve, reject) => {
11
- relyingParty.authenticate("https://steamcommunity.com/openid", false, (err, url) => {
6
+ import { redirect } from "react-router";
7
+ import { Strategy } from "remix-auth/strategy";
8
+ import SteamAPI, {} from "steamapi";
9
+ export class SteamStrategy extends Strategy {
10
+ options;
11
+ name = "steam";
12
+ constructor(options, verify) {
13
+ super(verify);
14
+ this.options = options;
15
+ }
16
+ authenticateToSteam(relyingParty) {
17
+ return new Promise((resolve, reject) => relyingParty.authenticate("https://steamcommunity.com/openid", false, (err, url) => {
12
18
  if (err) {
13
19
  return reject(err);
14
20
  }
15
21
  if (!url) {
16
- return reject("Got no URL from authenticate method");
22
+ return reject("Got no URL from authenticate method.");
17
23
  }
18
24
  return resolve(url);
19
- });
20
- });
21
- }
22
- function verifySteamAssertion(relyingParty, request) {
23
- return new Promise((resolve, reject) => {
24
- relyingParty.verifyAssertion(request, (err, result) => {
25
+ }));
26
+ }
27
+ verifySteamAssertion(relyingParty, request) {
28
+ return new Promise((resolve, reject) => relyingParty.verifyAssertion(request, (err, result) => {
25
29
  if (err) {
26
30
  return reject(err);
27
31
  }
28
32
  if (!result) {
29
- return reject("No result from verifyAssertion");
33
+ return reject("No result from verifyAssertion.");
30
34
  }
31
35
  return resolve(result);
32
- });
33
- });
34
- }
35
- export class SteamStrategy extends Strategy {
36
- options;
37
- name = "steam";
38
- constructor(options, verify) {
39
- super(verify);
40
- this.options = options;
36
+ }));
41
37
  }
42
- async authenticate(request, sessionStorage, options) {
38
+ async authenticate(request) {
43
39
  const { apiKey, onError, returnURL, realm } = typeof this.options === "function" ? await this.options(request) : this.options;
44
- const notifyError = (error) => {
40
+ const handleError = (error) => {
45
41
  if (!(error instanceof Response)) {
46
42
  onError?.(error);
47
43
  }
@@ -52,34 +48,27 @@ export class SteamStrategy extends Strategy {
52
48
  const url = new URL(request.url);
53
49
  const callbackUrl = new URL(returnURL);
54
50
  if (url.pathname === callbackUrl.pathname) {
55
- const result = await verifySteamAssertion(relyingParty, request);
56
- if (!result.authenticated || !result.claimedIdentifier)
57
- return this.failure(`Not authenticated from result`, request, sessionStorage, options);
58
- try {
59
- const userSteamID = result.claimedIdentifier.toString().split("/").at(-1);
60
- const steamUserSummary = (await steamApi.getUserSummary(userSteamID));
61
- const user = await this.verify({ user: steamUserSummary, request });
62
- return this.success(user, request, sessionStorage, options);
51
+ const result = await this.verifySteamAssertion(relyingParty, request);
52
+ if (!result.authenticated || !result.claimedIdentifier) {
53
+ throw new Error("Not authenticated from result.");
63
54
  }
64
- catch (error) {
65
- notifyError(error);
66
- let message = error.message;
67
- return this.failure(message, request, sessionStorage, options);
55
+ const userId = result.claimedIdentifier.toString().split("/").at(-1);
56
+ if (userId === undefined) {
57
+ throw new Error("Unable to get SteamID.");
68
58
  }
59
+ return await this.verify({
60
+ user: (await steamApi.getUserSummary(userId)),
61
+ request
62
+ });
69
63
  }
70
64
  else {
71
- try {
72
- throw redirect(await authenticateToSteam(relyingParty));
73
- }
74
- catch (error) {
75
- notifyError(error);
76
- throw error;
77
- }
65
+ throw redirect(await this.authenticateToSteam(relyingParty));
78
66
  }
79
67
  }
80
68
  catch (error) {
81
- notifyError(error);
69
+ handleError(error);
82
70
  throw error;
83
71
  }
84
72
  }
85
73
  }
74
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,QAAQ,EAAE,EAAoB,MAAM,UAAU,CAAC;AAgBtD,MAAM,OAAO,aAAoB,SAAQ,QAA2C;IAIpE;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,CAAgB;oBAC5D,OAAO;iBACV,CAAC,CAAC;YACP,CAAC;iBAAM,CAAC;gBACJ,MAAM,QAAQ,CAAC,MAAM,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC;YACjE,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,WAAW,CAAC,KAAK,CAAC,CAAC;YACnB,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ"}
package/package.json CHANGED
@@ -16,33 +16,28 @@
16
16
  "strategy"
17
17
  ],
18
18
  "scripts": {
19
+ "docs": "typedoc --out docs src/index.ts",
19
20
  "prepack": "([ -d dist ] && rm -rf dist); tsc",
20
21
  "typecheck": "tsc --project tsconfig.json --noEmit",
21
22
  "format": "prettier . --write",
22
23
  "upgrade": "npx npm-check-updates@latest --target minor -u"
23
24
  },
24
25
  "peerDependencies": {
25
- "@remix-run/server-runtime": "^2.8.1"
26
+ "react-router": "^7.0.1",
27
+ "remix-auth": "^4.0.0"
26
28
  },
27
29
  "devDependencies": {
28
- "@babel/core": "^7.25.2",
29
- "@babel/preset-env": "^7.25.4",
30
- "@babel/preset-react": "^7.24.7",
31
- "@babel/preset-typescript": "^7.24.7",
32
- "@remix-run/node": "^2.11.2",
33
- "@remix-run/react": "^2.11.2",
34
- "@remix-run/server-runtime": "^2.11.2",
35
- "@types/node": "^20.16.1",
30
+ "@total-typescript/tsconfig": "^1.0.4",
31
+ "@types/node": "^22.10.0",
36
32
  "@types/openid": "^2.0.5",
37
- "prettier": "^3.3.3",
38
- "react": "^18.3.1",
39
- "typescript": "^5.5.4"
33
+ "@types/steamapi": "^2.2.5",
34
+ "prettier": "^3.4.1",
35
+ "typedoc": "^0.27.0",
36
+ "typescript": "^5.7.2"
40
37
  },
41
38
  "dependencies": {
42
- "@types/steamapi": "^2.2.5",
43
39
  "openid": "^2.0.12",
44
- "remix-auth": "^3.7.0",
45
40
  "steamapi": "^3.0.12"
46
41
  },
47
- "version": "4.1.0"
42
+ "version": "5.0.1"
48
43
  }