Address some final review coments about cross-fetch and type-casting
This commit is contained in:
@@ -65,7 +65,6 @@
|
||||
"passport-okta-oauth": "^0.0.1",
|
||||
"passport-onelogin-oauth": "^0.0.1",
|
||||
"passport-saml": "^2.0.0",
|
||||
"r2": "^2.0.1",
|
||||
"uuid": "^8.0.0",
|
||||
"winston": "^3.2.1",
|
||||
"yn": "^4.0.0"
|
||||
|
||||
@@ -81,13 +81,7 @@ describe('TokenFactory', () => {
|
||||
const token = await factory.issueToken({ claims: { sub: 'foo' } });
|
||||
|
||||
const { keys } = await factory.listPublicKeys();
|
||||
const keyMap: {
|
||||
[key: string]: AnyJWK;
|
||||
} = {};
|
||||
|
||||
keys.forEach(key => {
|
||||
keyMap[key.kid] = key;
|
||||
});
|
||||
const keyMap = Object.fromEntries(keys.map(key => [key.kid, key]));
|
||||
|
||||
const payload = (
|
||||
await jwtVerify(token, async header => {
|
||||
|
||||
@@ -133,7 +133,6 @@ export class TokenFactory implements TokenIssuer {
|
||||
const kid = uuid();
|
||||
const jwk = await fromKeyLike(key.privateKey);
|
||||
|
||||
// @ts-ignore https://github.com/microsoft/TypeScript/issues/13195 -
|
||||
// JOSE Library provides optional for most fields - and TS does not distinguish between missing/undefined.
|
||||
// Because AnyJWK requires keys to have type "string", this throws a TypeError - though in practice, if the field
|
||||
// is undefined, JOSE will not send it back as key.
|
||||
@@ -142,7 +141,7 @@ export class TokenFactory implements TokenIssuer {
|
||||
alg: 'ES256',
|
||||
kid: kid,
|
||||
use: 'sig',
|
||||
};
|
||||
} as AnyJWK;
|
||||
// We're not allowed to use the key until it has been successfully stored
|
||||
// TODO: some token verification implementations aggressively cache the list of keys, and
|
||||
// don't attempt to fetch new ones even if they encounter an unknown kid. Therefore we
|
||||
|
||||
@@ -30,11 +30,13 @@ yOlxJ2VW88mLAQGJ7HPAvOdylxZsItMnzCuqNzZvie8m/NJsOjhDncVkrw==
|
||||
`;
|
||||
};
|
||||
|
||||
jest.mock('r2', () => ({
|
||||
jest.mock('cross-fetch', () => ({
|
||||
__esModule: true,
|
||||
default: () => {
|
||||
default: async () => {
|
||||
return {
|
||||
text: mockKey(),
|
||||
json: async () => {
|
||||
return mockKey();
|
||||
},
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -19,8 +19,7 @@ import {
|
||||
ExperimentalIdentityResolver,
|
||||
} from '../types';
|
||||
import express from 'express';
|
||||
// @ts-ignore no types available for R2
|
||||
import r2 from 'r2';
|
||||
import fetch from 'cross-fetch';
|
||||
import * as crypto from 'crypto';
|
||||
import { KeyObject } from 'crypto';
|
||||
import { Logger } from 'winston';
|
||||
@@ -101,9 +100,9 @@ export class AwsAlbAuthProvider implements AuthProviderRouteHandlers {
|
||||
if (optionalCacheKey) {
|
||||
return optionalCacheKey;
|
||||
}
|
||||
const keyText: string = await r2(
|
||||
const keyText: string = await fetch(
|
||||
`https://public-keys.auth.elb.${this.options.region}.amazonaws.com/${keyId}`,
|
||||
).text;
|
||||
).then(response => response.json());
|
||||
const keyValue = crypto.createPublicKey(keyText);
|
||||
this.keyCache.set(keyId, keyValue);
|
||||
return keyValue;
|
||||
|
||||
@@ -9781,7 +9781,7 @@ case-sensitive-paths-webpack-plugin@^2.2.0:
|
||||
resolved "https://registry.npmjs.org/case-sensitive-paths-webpack-plugin/-/case-sensitive-paths-webpack-plugin-2.3.0.tgz#23ac613cc9a856e4f88ff8bb73bbb5e989825cf7"
|
||||
integrity sha512-/4YgnZS8y1UXXmC02xD5rRrBEu6T5ub+mQHLNRj0fzTRbgdBYhsNo2V5EqwgqrExjxsjtF/OpAKAMkKsxbD5XQ==
|
||||
|
||||
caseless@^0.12.0, caseless@~0.12.0:
|
||||
caseless@~0.12.0:
|
||||
version "0.12.0"
|
||||
resolved "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
|
||||
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
|
||||
@@ -18834,7 +18834,7 @@ node-fetch-npm@^2.0.2:
|
||||
json-parse-better-errors "^1.0.0"
|
||||
safe-buffer "^5.1.1"
|
||||
|
||||
node-fetch@2.6.1, node-fetch@^2.0.0-alpha.8, node-fetch@^2.1.2, node-fetch@^2.2.0, node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1:
|
||||
node-fetch@2.6.1, node-fetch@^2.1.2, node-fetch@^2.2.0, node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||
@@ -21216,15 +21216,6 @@ quick-lru@^5.1.1:
|
||||
resolved "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932"
|
||||
integrity sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==
|
||||
|
||||
r2@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.npmjs.org/r2/-/r2-2.0.1.tgz#94cd802ecfce9a622549c8182032d8e4a2b2e612"
|
||||
integrity sha512-EEmxoxYCe3LHzAUhRIRxdCKERpeRNmlLj6KLUSORqnK6dWl/K5ShmDGZqM2lRZQeqJgF+wyqk0s1M7SWUveNOQ==
|
||||
dependencies:
|
||||
caseless "^0.12.0"
|
||||
node-fetch "^2.0.0-alpha.8"
|
||||
typedarray-to-buffer "^3.1.2"
|
||||
|
||||
raf-schd@^4.0.2:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.npmjs.org/raf-schd/-/raf-schd-4.0.2.tgz#bd44c708188f2e84c810bf55fcea9231bcaed8a0"
|
||||
@@ -25021,7 +25012,7 @@ typed-rest-client@^1.8.0:
|
||||
tunnel "0.0.6"
|
||||
underscore "1.8.3"
|
||||
|
||||
typedarray-to-buffer@^3.1.2, typedarray-to-buffer@^3.1.5:
|
||||
typedarray-to-buffer@^3.1.5:
|
||||
version "3.1.5"
|
||||
resolved "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
|
||||
integrity sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==
|
||||
|
||||
Reference in New Issue
Block a user