ag-common 0.0.90 → 0.0.91

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.
@@ -1,7 +1,8 @@
1
1
  import { error } from '../../common/helpers/log';
2
2
  import { User } from '../../ui/helpers/jwt';
3
3
  import { APIGatewayProxyResult } from '../types';
4
- export declare const getAndValidateToken: ({ tokenRaw, COGNITO_USER_POOL_ID, }: {
4
+ export declare const getAndValidateToken: ({ tokenRaw, jwksRegion, COGNITO_USER_POOL_ID, }: {
5
+ jwksRegion?: string | undefined;
5
6
  tokenRaw?: string | undefined;
6
7
  COGNITO_USER_POOL_ID: string;
7
8
  }) => Promise<{
@@ -19,9 +19,7 @@ const jsonwebtoken_1 = require("jsonwebtoken");
19
19
  const log_1 = require("../../common/helpers/log");
20
20
  const api_1 = require("./api");
21
21
  let jwksClient;
22
- const jwtVerify = ({ COGNITO_USER_POOL_ID, token, }) => __awaiter(void 0, void 0, void 0, function* () {
23
- const jwksUri = `https://cognito-idp.ap-southeast-2.amazonaws.com/${COGNITO_USER_POOL_ID}/.well-known/jwks.json`;
24
- const issuer = `https://cognito-idp.ap-southeast-2.amazonaws.com/${COGNITO_USER_POOL_ID}`;
22
+ const jwtVerify = ({ token, jwksUri, issuer, }) => __awaiter(void 0, void 0, void 0, function* () {
25
23
  return new Promise((resolve, reject) => {
26
24
  (0, jsonwebtoken_1.verify)(token, (header, callback) => {
27
25
  if (!jwksClient) {
@@ -60,8 +58,10 @@ const jwtVerify = ({ COGNITO_USER_POOL_ID, token, }) => __awaiter(void 0, void 0
60
58
  });
61
59
  });
62
60
  });
63
- const getAndValidateToken = ({ tokenRaw, COGNITO_USER_POOL_ID, }) => __awaiter(void 0, void 0, void 0, function* () {
61
+ const getAndValidateToken = ({ tokenRaw, jwksRegion = 'ap-southeast-2', COGNITO_USER_POOL_ID, }) => __awaiter(void 0, void 0, void 0, function* () {
64
62
  var _a, _b;
63
+ const jwksUri = `https://cognito-idp.${jwksRegion}.amazonaws.com/${COGNITO_USER_POOL_ID}/.well-known/jwks.json`;
64
+ const issuer = `https://cognito-idp.${jwksRegion}.amazonaws.com/${COGNITO_USER_POOL_ID}`;
65
65
  let token = '';
66
66
  try {
67
67
  if (!tokenRaw) {
@@ -73,7 +73,7 @@ const getAndValidateToken = ({ tokenRaw, COGNITO_USER_POOL_ID, }) => __awaiter(v
73
73
  token = tokenRaw.substring(tokenRaw.indexOf(' ') + 1);
74
74
  let subject;
75
75
  try {
76
- yield jwtVerify({ token, COGNITO_USER_POOL_ID });
76
+ yield jwtVerify({ token, jwksUri, issuer });
77
77
  const decoded = (0, jsonwebtoken_1.decode)(token);
78
78
  (0, log_1.debug)(`decoded=${JSON.stringify(decoded, null, 2)}`);
79
79
  subject = decoded === null || decoded === void 0 ? void 0 : decoded.sub;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.90",
3
+ "version": "0.0.91",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",