1- const openIdClient = require ( 'openid-client' ) ;
2- const { Strategy } = require ( 'openid-client/passport' ) ;
31const passport = require ( 'passport' ) ;
42const db = require ( '../../db' ) ;
53
64let type ;
75
86const 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