passport-steam-openid 1.1.0 → 1.1.2

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.
@@ -13,7 +13,7 @@ jobs:
13
13
 
14
14
  - uses: actions/setup-node@v3
15
15
  with:
16
- node-version: 18
16
+ node-version: 20
17
17
  name: Setup Node.JS
18
18
 
19
19
  - run: npm ci
@@ -12,7 +12,7 @@ jobs:
12
12
 
13
13
  - uses: actions/setup-node@v3
14
14
  with:
15
- node-version: '18'
15
+ node-version: 20
16
16
  name: Setup Node.JS
17
17
 
18
18
  - name: Install packages
package/README.md CHANGED
@@ -5,6 +5,56 @@ This package only relies on [passport](https://www.passportjs.org/) and [axios](
5
5
 
6
6
  Library is fully covered with tests, both unit and integration tests to make sure everything runs correctly.
7
7
 
8
+ ## API
9
+
10
+ Instantiate the `SteamOpenIdStrategy` as following:
11
+ ```ts
12
+ new SteamOpenIdStrategy(options, verify)
13
+ ```
14
+
15
+ Options object has the following properties:
16
+ - `returnURL` - URL to which steam will redirect user after authentication
17
+ - `profile` - If set to true, it will fetch user profile from steam api, otherwise only steamid will be returned
18
+ - `apiKey` - Steam api key, required if `options.profile` is set to true
19
+ - `maxNonceTimeDelay` - Optional, in seconds, time between creation and verification of nonce date, if not set no verification occurs.
20
+
21
+ Second parameter of `SteamOpenIdStrategy` is a callback function used for verifying logged in user, with the following parameters:
22
+ - `req` - Express request object
23
+ - `steamid` - Steam id of the authenticated user
24
+ - `profile` - Full profile from GetPlayerSummaries api, if `options.profile` is set to true, otherwise only steamid
25
+ - `done` - Passport callback function
26
+
27
+ Profile if `options.profile` is set to true:
28
+ ```ts
29
+ export type SteamOpenIdUserProfile = {
30
+ steamid: string;
31
+ communityvisibilitystate: number;
32
+ profilestate: number;
33
+ personaname: string;
34
+ commentpermission: number;
35
+ profileurl: string;
36
+ avatar: string;
37
+ avatarmedium: string;
38
+ avatarfull: string;
39
+ avatarhash: string;
40
+ lastlogoff: number;
41
+ personastate: number;
42
+ realname: string;
43
+ primaryclanid: string;
44
+ timecreated: number;
45
+ personastateflags: number;
46
+ loccountrycode: string;
47
+ locstatecode: string;
48
+ };
49
+ ```
50
+
51
+ Other it is just:
52
+ ```ts
53
+ export type SteamOpenIdUser = {
54
+ steamid: string;
55
+ };
56
+ ```
57
+
8
58
  ## Usage
9
59
  ```ts
10
60
  import { SteamOpenIdStrategy } from 'passport-steam-openid';
@@ -13,11 +63,12 @@ passport.use(
13
63
  new SteamOpenIdStrategy({
14
64
  returnURL: 'http://localhost:3000/auth/steam',
15
65
  profile: true,
16
- apiKey: '<insert steam api key>'
66
+ apiKey: '<insert steam api key>', // No need for api key, if profile is set to false
67
+ maxNonceTimeDelay: 30 // Optional, in seconds, time between creation and verification of nonce date
17
68
  }, (
18
69
  req: Request,
19
70
  identifier: string,
20
- profile: SteamOpenIdUserProfile,
71
+ profile: SteamOpenIdUserProfile, // if profile is false, then it's only { steamid }, otherwise full profile from GetPlayerSummaries api
21
72
  done: VerifyCallback
22
73
  ) => {
23
74
  // Optional callback called only when successful authentication occurs
@@ -44,6 +95,8 @@ app.use(
44
95
  // Steam rejected this authentication request
45
96
  case SteamOpenIdErrorType.InvalidSteamId:
46
97
  // Steam profile doesn't exist
98
+ case SteamOpenIdErrorType.NonceExpired:
99
+ // Nonce has expired, only if `options.maxNonceTimeDelay` is set
47
100
  }
48
101
  }
49
102
  // ...
@@ -59,6 +112,7 @@ Install using npm:
59
112
  ```
60
113
  npm install passport-steam-openid
61
114
  ```
115
+
62
116
  Library's API has been unchanged and stable for some time now. It will not change unless a breaking change is issued by steam (very unlikely).
63
117
 
64
118
  ## License
@@ -1 +1 @@
1
- {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":";AAAA,OAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACjD,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM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,MAAM,GAAG,OAAO;IASpD;;;;;;OAMG;IACH,SAAS,CAAC,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAoBzE;;;;OAIG;IACH,SAAS,CAAC,8BAA8B,CAAC,KAAK,EAAE,gBAAgB;IAMhE;;;;;;OAMG;IACH,SAAS,CAAC,oBAAoB,CAAC,QAAQ,EAAE,GAAG;IAQ5C;;;;;OAKG;IACH,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,gBAAgB;IAM5C;;;;;;;;OAQG;cACa,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IASxD;;;;;;;;;;OAUG;cACa,kBAAkB,CAChC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,sBAAsB,CAAC;CA+BnC"}
package/dist/strategy.js CHANGED
@@ -303,27 +303,24 @@ class SteamOpenIdStrategy extends passport_1.Strategy {
303
303
  * @throws {SteamOpenIdError} if profile was not found
304
304
  */
305
305
  fetchPlayerSummary(steamId) {
306
+ var _a;
306
307
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
307
308
  const summaryQuery = {
308
309
  steamids: steamId,
309
310
  key: this.apiKey,
310
311
  };
311
- return this.axios
312
- .get(`${constant_1.PLAYER_SUMMARY_URL}/?${querystring_1.default.stringify(summaryQuery)}`)
313
- .then(({ data }) => {
314
- var _a;
315
- if (!Array.isArray((_a = data === null || data === void 0 ? void 0 : data.response) === null || _a === void 0 ? void 0 : _a.players)) {
316
- throw new Error('Malformed response from steam.');
317
- }
318
- const user = data.response.players[0];
319
- if (!user) {
320
- throw new error_1.SteamOpenIdError('Profile was not found on steam.', type_1.SteamOpenIdErrorType.InvalidSteamId);
321
- }
322
- if (user.steamid != steamId) {
323
- throw new error_1.SteamOpenIdError('API returned invalid user.', type_1.SteamOpenIdErrorType.InvalidSteamId);
324
- }
325
- return user;
326
- });
312
+ const { data } = yield this.axios.get(`${constant_1.PLAYER_SUMMARY_URL}/?${querystring_1.default.stringify(summaryQuery)}`);
313
+ if (!Array.isArray((_a = data === null || data === void 0 ? void 0 : data.response) === null || _a === void 0 ? void 0 : _a.players)) {
314
+ throw new Error('Malformed response from steam.');
315
+ }
316
+ const user = data.response.players[0];
317
+ if (!user) {
318
+ throw new error_1.SteamOpenIdError('Profile was not found on steam.', type_1.SteamOpenIdErrorType.InvalidSteamId);
319
+ }
320
+ if (user.steamid != steamId) {
321
+ throw new error_1.SteamOpenIdError('API returned invalid user.', type_1.SteamOpenIdErrorType.InvalidSteamId);
322
+ }
323
+ return user;
327
324
  });
328
325
  }
329
326
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passport-steam-openid",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Passport strategy for authenticating with steam openid without the use of 3rd party openid packages.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -51,7 +51,7 @@
51
51
  "nock": "^13.3.2",
52
52
  "nyc": "^15.1.0",
53
53
  "prettier": "^2.8.8",
54
- "semantic-release": "^21.0.5",
54
+ "semantic-release": "^24.0.0",
55
55
  "sinon": "^15.2.0",
56
56
  "ts-node": "^10.9.1",
57
57
  "typescript": "^5.1.3"
@@ -744,12 +744,12 @@
744
744
  }
745
745
  },
746
746
  "node_modules/braces": {
747
- "version": "3.0.2",
748
- "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
749
- "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
747
+ "version": "3.0.3",
748
+ "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
749
+ "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
750
750
  "dev": true,
751
751
  "dependencies": {
752
- "fill-range": "^7.0.1"
752
+ "fill-range": "^7.1.1"
753
753
  },
754
754
  "engines": {
755
755
  "node": ">=8"
@@ -1426,9 +1426,9 @@
1426
1426
  }
1427
1427
  },
1428
1428
  "node_modules/fill-range": {
1429
- "version": "7.0.1",
1430
- "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
1431
- "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
1429
+ "version": "7.1.1",
1430
+ "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
1431
+ "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
1432
1432
  "dev": true,
1433
1433
  "dependencies": {
1434
1434
  "to-regex-range": "^5.0.1"
package/src/strategy.ts CHANGED
@@ -399,31 +399,29 @@ export class SteamOpenIdStrategy<
399
399
  key: this.apiKey,
400
400
  };
401
401
 
402
- return this.axios
403
- .get<SteamPlayerSummaryResponse>(
404
- `${PLAYER_SUMMARY_URL}/?${qs.stringify(summaryQuery)}`,
405
- )
406
- .then(({ data }) => {
407
- if (!Array.isArray(data?.response?.players)) {
408
- throw new Error('Malformed response from steam.');
409
- }
402
+ const { data } = await this.axios.get<SteamPlayerSummaryResponse>(
403
+ `${PLAYER_SUMMARY_URL}/?${qs.stringify(summaryQuery)}`,
404
+ );
410
405
 
411
- const user = data.response.players[0];
412
- if (!user) {
413
- throw new SteamOpenIdError(
414
- 'Profile was not found on steam.',
415
- SteamOpenIdErrorType.InvalidSteamId,
416
- );
417
- }
406
+ if (!Array.isArray(data?.response?.players)) {
407
+ throw new Error('Malformed response from steam.');
408
+ }
418
409
 
419
- if (user.steamid != steamId) {
420
- throw new SteamOpenIdError(
421
- 'API returned invalid user.',
422
- SteamOpenIdErrorType.InvalidSteamId,
423
- );
424
- }
410
+ const user = data.response.players[0];
411
+ if (!user) {
412
+ throw new SteamOpenIdError(
413
+ 'Profile was not found on steam.',
414
+ SteamOpenIdErrorType.InvalidSteamId,
415
+ );
416
+ }
425
417
 
426
- return user;
427
- });
418
+ if (user.steamid != steamId) {
419
+ throw new SteamOpenIdError(
420
+ 'API returned invalid user.',
421
+ SteamOpenIdErrorType.InvalidSteamId,
422
+ );
423
+ }
424
+
425
+ return user;
428
426
  }
429
427
  }