1
- const openIdClient = require ( 'openid-client' ) ;
2
- const { Strategy } = require ( 'openid-client/passport' ) ;
3
1
const passport = require ( 'passport' ) ;
4
2
const db = require ( '../../db' ) ;
5
3
6
4
const configure = async ( ) => {
5
+ // Temp fix for ERR_REQUIRE_ESM, will be changed when we refactor to ESM
6
+ const { discovery, fetchUserInfo } = await import ( 'openid-client' ) ;
7
+ const { Strategy } = await import ( 'openid-client/passport' ) ;
7
8
const config = require ( '../../config' ) . getAuthentication ( ) ;
8
9
const { oidcConfig } = config ;
9
10
const { issuer, clientID, clientSecret, callbackURL, scope } = oidcConfig ;
@@ -15,13 +16,13 @@ const configure = async () => {
15
16
const server = new URL ( issuer ) ;
16
17
17
18
try {
18
- const config = await openIdClient . discovery ( server , clientID , clientSecret ) ;
19
+ const config = await discovery ( server , clientID , clientSecret ) ;
19
20
20
21
const strategy = new Strategy ( { callbackURL, config, scope } , async ( tokenSet , done ) => {
21
22
// Validate token sub for added security
22
23
const idTokenClaims = tokenSet . claims ( ) ;
23
24
const expectedSub = idTokenClaims . sub ;
24
- const userInfo = await openIdClient . fetchUserInfo ( config , tokenSet . access_token , expectedSub ) ;
25
+ const userInfo = await fetchUserInfo ( config , tokenSet . access_token , expectedSub ) ;
25
26
handleUserAuthentication ( userInfo , done ) ;
26
27
} ) ;
27
28
0 commit comments