@ianlucas/remix-auth-steam 4.1.0-beta.1 → 5.0.0
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 +4 -5
- package/dist/index.js +35 -46
- package/dist/index.js.map +1 -0
- package/package.json +10 -15
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { UserSummary } from "steamapi";
|
|
1
|
+
import { Strategy } from "remix-auth/strategy";
|
|
2
|
+
import { type UserSummary } from "steamapi";
|
|
4
3
|
export interface SteamStrategyOptions {
|
|
5
4
|
apiKey: string;
|
|
6
5
|
onError?: (error: unknown) => void;
|
|
@@ -14,6 +13,6 @@ export type SteamStrategyVerifyParams = {
|
|
|
14
13
|
export declare class SteamStrategy<User> extends Strategy<User, SteamStrategyVerifyParams> {
|
|
15
14
|
private options;
|
|
16
15
|
name: string;
|
|
17
|
-
constructor(options: SteamStrategyOptions | ((request: Request) => Promise<SteamStrategyOptions>), verify:
|
|
18
|
-
authenticate(request: Request
|
|
16
|
+
constructor(options: SteamStrategyOptions | ((request: Request) => Promise<SteamStrategyOptions>), verify: Strategy.VerifyFunction<User, SteamStrategyVerifyParams>);
|
|
17
|
+
authenticate(request: Request): Promise<User>;
|
|
19
18
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,35 +2,31 @@
|
|
|
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 {
|
|
8
|
-
import
|
|
6
|
+
import { redirect } from "react-router";
|
|
7
|
+
import { Strategy } from "remix-auth/strategy";
|
|
8
|
+
import SteamAPI, {} from "steamapi";
|
|
9
9
|
function authenticateToSteam(relyingParty) {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
});
|
|
10
|
+
return new Promise((resolve, reject) => relyingParty.authenticate("https://steamcommunity.com/openid", false, (err, url) => {
|
|
11
|
+
if (err) {
|
|
12
|
+
return reject(err);
|
|
13
|
+
}
|
|
14
|
+
if (!url) {
|
|
15
|
+
return reject("Got no URL from authenticate method");
|
|
16
|
+
}
|
|
17
|
+
return resolve(url);
|
|
18
|
+
}));
|
|
21
19
|
}
|
|
22
20
|
function verifySteamAssertion(relyingParty, request) {
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
});
|
|
21
|
+
return new Promise((resolve, reject) => relyingParty.verifyAssertion(request, (err, result) => {
|
|
22
|
+
if (err) {
|
|
23
|
+
return reject(err);
|
|
24
|
+
}
|
|
25
|
+
if (!result) {
|
|
26
|
+
return reject("No result from verifyAssertion");
|
|
27
|
+
}
|
|
28
|
+
return resolve(result);
|
|
29
|
+
}));
|
|
34
30
|
}
|
|
35
31
|
export class SteamStrategy extends Strategy {
|
|
36
32
|
options;
|
|
@@ -39,9 +35,9 @@ export class SteamStrategy extends Strategy {
|
|
|
39
35
|
super(verify);
|
|
40
36
|
this.options = options;
|
|
41
37
|
}
|
|
42
|
-
async authenticate(request
|
|
38
|
+
async authenticate(request) {
|
|
43
39
|
const { apiKey, onError, returnURL, realm } = typeof this.options === "function" ? await this.options(request) : this.options;
|
|
44
|
-
const
|
|
40
|
+
const handleError = (error) => {
|
|
45
41
|
if (!(error instanceof Response)) {
|
|
46
42
|
onError?.(error);
|
|
47
43
|
}
|
|
@@ -53,33 +49,26 @@ export class SteamStrategy extends Strategy {
|
|
|
53
49
|
const callbackUrl = new URL(returnURL);
|
|
54
50
|
if (url.pathname === callbackUrl.pathname) {
|
|
55
51
|
const result = await verifySteamAssertion(relyingParty, request);
|
|
56
|
-
if (!result.authenticated || !result.claimedIdentifier)
|
|
57
|
-
|
|
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);
|
|
52
|
+
if (!result.authenticated || !result.claimedIdentifier) {
|
|
53
|
+
throw new Error("Not authenticated from result");
|
|
63
54
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
72
|
-
throw redirect(await authenticateToSteam(relyingParty));
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
notifyError(error);
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
65
|
+
throw redirect(await authenticateToSteam(relyingParty));
|
|
78
66
|
}
|
|
79
67
|
}
|
|
80
68
|
catch (error) {
|
|
81
|
-
|
|
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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rE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBACvB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;gBAC9C,CAAC;gBACD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC;oBACrB,IAAI,EAAE,CAAC,MAAM,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAgB;oBAC5D,OAAO;iBACV,CAAC,CAAC;YACP,CAAC;iBAAM,CAAC;gBACJ,MAAM,QAAQ,CAAC,MAAM,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC;YAC5D,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
|
-
"
|
|
26
|
+
"react-router": "^7.0.1",
|
|
27
|
+
"remix-auth": "^4.0.0"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
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
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
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": "
|
|
42
|
+
"version": "5.0.0"
|
|
48
43
|
}
|