Skip to content

Commit 2f19f82

Browse files
committed
fix(auth): try to fix ESM issue on openid-client import
1 parent 291c179 commit 2f19f82

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/service/passport/oidc.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const openIdClient = require('openid-client');
2-
const { Strategy } = require('openid-client/passport');
31
const passport = require('passport');
42
const db = require('../../db');
53

64
let type;
75

86
const configure = async () => {
7+
// Temp fix for ERR_REQUIRE_ESM, will be changed when we refactor to ESM
8+
const { discovery, fetchUserInfo } = await import('openid-client');
9+
const { Strategy } = await import('openid-client/passport');
910
const authMethods = require('../../config').getAuthMethods();
1011
const oidcConfig = authMethods.find((method) => method.type.toLowerCase() === "openidconnect")?.oidcConfig;
1112
const { issuer, clientID, clientSecret, callbackURL, scope } = oidcConfig;
@@ -17,13 +18,13 @@ const configure = async () => {
1718
const server = new URL(issuer);
1819

1920
try {
20-
const config = await openIdClient.discovery(server, clientID, clientSecret);
21+
const config = await discovery(server, clientID, clientSecret);
2122

2223
const strategy = new Strategy({ callbackURL, config, scope }, async (tokenSet, done) => {
2324
// Validate token sub for added security
2425
const idTokenClaims = tokenSet.claims();
2526
const expectedSub = idTokenClaims.sub;
26-
const userInfo = await openIdClient.fetchUserInfo(config, tokenSet.access_token, expectedSub);
27+
const userInfo = await fetchUserInfo(config, tokenSet.access_token, expectedSub);
2728
handleUserAuthentication(userInfo, done);
2829
});
2930

0 commit comments

Comments
 (0)