-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,47 @@ | ||
import { custom, Issuer } from 'openid-client'; | ||
import passport from 'passport'; | ||
import { custom, Issuer } from "openid-client"; | ||
import passport from "passport"; | ||
|
||
import { googleStrategy } from './strategy/google'; | ||
import { getMicrosoftOidcStrategy, getMicrosoftClientConfig, MICROSOFT_OPENID_CONFIG_URL } from './strategy/microsoft-oidc'; | ||
import { googleStrategy } from "./strategy/google"; | ||
import { | ||
getMicrosoftOidcStrategy, | ||
getMicrosoftClientConfig, | ||
MICROSOFT_OPENID_CONFIG_URL, | ||
} from "./strategy/microsoft-oidc"; | ||
|
||
const setupPassport = () => { | ||
// TODO: remove below config (timeout extended for local testing with poor connection) | ||
custom.setHttpOptionsDefaults({ | ||
timeout: 10000, | ||
}) | ||
}); | ||
|
||
// explicitly instantiate new passport for clarity | ||
let passportWithStrategies = new passport.Passport() | ||
const passportWithStrategies = new passport.Passport(); | ||
|
||
// build Microsoft OIDC client, and use it to build the related strategy | ||
let microsoftOidcClient; | ||
Issuer.discover(MICROSOFT_OPENID_CONFIG_URL).then(microsoftIssuer => { | ||
Issuer.discover(MICROSOFT_OPENID_CONFIG_URL).then((microsoftIssuer) => { | ||
console.debug("Discovered issuer %s", microsoftIssuer.issuer); | ||
const microsoftClientConfig = getMicrosoftClientConfig(); | ||
microsoftOidcClient = new microsoftIssuer.Client(microsoftClientConfig); | ||
console.debug("Built Microsoft client: %O", microsoftOidcClient); | ||
passportWithStrategies.use('microsoft-oidc', getMicrosoftOidcStrategy(microsoftOidcClient)); | ||
passportWithStrategies.use( | ||
"microsoft-oidc", | ||
getMicrosoftOidcStrategy(microsoftOidcClient), | ||
); | ||
}); | ||
|
||
// do any other aspects of passport setup which can be handled here | ||
passportWithStrategies.use('google', googleStrategy); | ||
passportWithStrategies.use("google", googleStrategy); | ||
passportWithStrategies.serializeUser((user: any, done) => { | ||
done(null, user); | ||
}); | ||
passportWithStrategies.deserializeUser((obj: any, done) => { | ||
done(null, obj); | ||
}); | ||
return { passportWithStrategies, microsoftOidcClient } | ||
} | ||
|
||
return { passportWithStrategies, microsoftOidcClient }; | ||
}; | ||
|
||
// instantiate and export the new passport class and Microsoft client as early as possible | ||
let { passportWithStrategies, microsoftOidcClient } = setupPassport(); | ||
export { passportWithStrategies, microsoftOidcClient }; | ||
const { passportWithStrategies, microsoftOidcClient } = setupPassport(); | ||
export { passportWithStrategies, microsoftOidcClient }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters