@ianlucas/remix-auth-steam 2.0.2 → 2.1.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/README.md +1 -1
- package/dist/index.js +30 -6
- package/package.json +1 -1
- package/dist/promises.d.ts +0 -6
- package/dist/promises.js +0 -26
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,10 +3,35 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { redirect } from "@remix-run/server-runtime";
|
|
6
|
-
import { Strategy } from "remix-auth";
|
|
7
6
|
import OpenID from "openid";
|
|
8
|
-
import {
|
|
7
|
+
import { Strategy } from "remix-auth";
|
|
9
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) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
return reject(err);
|
|
14
|
+
}
|
|
15
|
+
if (!url) {
|
|
16
|
+
return reject("Got no URL from authenticate method");
|
|
17
|
+
}
|
|
18
|
+
return resolve(url);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function verifySteamAssertion(relyingParty, request) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
relyingParty.verifyAssertion(request, (err, result) => {
|
|
25
|
+
if (err) {
|
|
26
|
+
return reject(err);
|
|
27
|
+
}
|
|
28
|
+
if (!result) {
|
|
29
|
+
return reject("No result from verifyAssertion");
|
|
30
|
+
}
|
|
31
|
+
return resolve(result);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
10
35
|
export class SteamStrategy extends Strategy {
|
|
11
36
|
name = "steam";
|
|
12
37
|
options;
|
|
@@ -15,11 +40,11 @@ export class SteamStrategy extends Strategy {
|
|
|
15
40
|
this.options = options;
|
|
16
41
|
}
|
|
17
42
|
async authenticate(request, sessionStorage, options) {
|
|
18
|
-
const { apiKey, returnURL, realm } = typeof this.options === "function" ? await this.options() : this.options;
|
|
43
|
+
const { apiKey, returnURL, realm } = typeof this.options === "function" ? await this.options(request) : this.options;
|
|
19
44
|
const relyingParty = new OpenID.RelyingParty(returnURL, realm ?? null, true, false, []);
|
|
20
45
|
const steamApi = new SteamAPI(apiKey);
|
|
21
46
|
try {
|
|
22
|
-
const result = await
|
|
47
|
+
const result = await verifySteamAssertion(relyingParty, request);
|
|
23
48
|
if (!result.authenticated || !result.claimedIdentifier)
|
|
24
49
|
return this.failure(`Not authenticated from result`, request, sessionStorage, options);
|
|
25
50
|
try {
|
|
@@ -34,8 +59,7 @@ export class SteamStrategy extends Strategy {
|
|
|
34
59
|
}
|
|
35
60
|
}
|
|
36
61
|
catch {
|
|
37
|
-
|
|
38
|
-
throw redirect(result);
|
|
62
|
+
throw redirect(await authenticateToSteam(relyingParty));
|
|
39
63
|
}
|
|
40
64
|
}
|
|
41
65
|
}
|
package/package.json
CHANGED
package/dist/promises.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type OpenID from "openid";
|
|
2
|
-
export declare const PromiseAuthenticate: (relyingParty: OpenID.RelyingParty) => Promise<string>;
|
|
3
|
-
export declare const PromiseVerifyAssertion: (relyingParty: OpenID.RelyingParty, req: Request) => Promise<{
|
|
4
|
-
authenticated: boolean;
|
|
5
|
-
claimedIdentifier?: string | undefined;
|
|
6
|
-
}>;
|
package/dist/promises.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Ian Lucas. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
export const PromiseAuthenticate = (relyingParty) => new Promise((resolve, reject) => {
|
|
6
|
-
relyingParty.authenticate("https://steamcommunity.com/openid", false, (err, url) => {
|
|
7
|
-
if (err) {
|
|
8
|
-
return reject(err);
|
|
9
|
-
}
|
|
10
|
-
if (!url) {
|
|
11
|
-
return reject("Got no URL from authenticate method");
|
|
12
|
-
}
|
|
13
|
-
return resolve(url);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
export const PromiseVerifyAssertion = (relyingParty, req) => new Promise((resolve, reject) => {
|
|
17
|
-
relyingParty.verifyAssertion(req, (err, result) => {
|
|
18
|
-
if (err) {
|
|
19
|
-
return reject(err);
|
|
20
|
-
}
|
|
21
|
-
if (!result) {
|
|
22
|
-
return reject(`No result from verifyAssertion`);
|
|
23
|
-
}
|
|
24
|
-
return resolve(result);
|
|
25
|
-
});
|
|
26
|
-
});
|