Merge pull request #9892 from StarZeus/develop

Configuration for Google Auth and OIDC Redirect URLs
This commit is contained in:
Martin McKeaveney 2023-03-06 17:30:01 +00:00 committed by GitHub
commit 1c4dcdf7c5
2 changed files with 19 additions and 4 deletions

View File

@ -204,13 +204,16 @@ export const googleCallback = async (ctx: any, next: any) => {
return passport.authenticate( return passport.authenticate(
strategy, strategy,
{ successRedirect: "/", failureRedirect: "/error" }, {
successRedirect: env.PASSPORT_GOOGLEAUTH_SUCCESS_REDIRECT,
failureRedirect: env.PASSPORT_GOOGLEAUTH_FAILURE_REDIRECT,
},
async (err: any, user: SSOUser, info: any) => { async (err: any, user: SSOUser, info: any) => {
await passportCallback(ctx, user, err, info) await passportCallback(ctx, user, err, info)
await context.identity.doInUserContext(user, ctx, async () => { await context.identity.doInUserContext(user, ctx, async () => {
await events.auth.login("google-internal", user.email) await events.auth.login("google-internal", user.email)
}) })
ctx.redirect("/") ctx.redirect(env.PASSPORT_GOOGLEAUTH_SUCCESS_REDIRECT)
} }
)(ctx, next) )(ctx, next)
} }
@ -269,13 +272,16 @@ export const oidcCallback = async (ctx: any, next: any) => {
return passport.authenticate( return passport.authenticate(
strategy, strategy,
{ successRedirect: "/", failureRedirect: "/error" }, {
successRedirect: env.PASSPORT_OIDCAUTH_SUCCESS_REDIRECT,
failureRedirect: env.PASSPORT_OIDCAUTH_FAILURE_REDIRECT,
},
async (err: any, user: SSOUser, info: any) => { async (err: any, user: SSOUser, info: any) => {
await passportCallback(ctx, user, err, info) await passportCallback(ctx, user, err, info)
await context.identity.doInUserContext(user, ctx, async () => { await context.identity.doInUserContext(user, ctx, async () => {
await events.auth.login("oidc", user.email) await events.auth.login("oidc", user.email)
}) })
ctx.redirect("/") ctx.redirect(env.PASSPORT_OIDCAUTH_SUCCESS_REDIRECT)
} }
)(ctx, next) )(ctx, next)
} }

View File

@ -69,6 +69,15 @@ const environment = {
* Mock the email service in use - links to ethereal hosted emails are logged instead. * Mock the email service in use - links to ethereal hosted emails are logged instead.
*/ */
ENABLE_EMAIL_TEST_MODE: process.env.ENABLE_EMAIL_TEST_MODE, ENABLE_EMAIL_TEST_MODE: process.env.ENABLE_EMAIL_TEST_MODE,
PASSPORT_GOOGLEAUTH_SUCCESS_REDIRECT:
process.env.PASSPORT_GOOGLEAUTH_SUCCESS_REDIRECT || "/",
PASSPORT_GOOGLEAUTH_FAILURE_REDIRECT:
process.env.PASSPORT_GOOGLEAUTH_FAILURE_REDIRECT || "/error",
PASSPORT_OIDCAUTH_SUCCESS_REDIRECT:
process.env.PASSPORT_OIDCAUTH_SUCCESS_REDIRECT || "/",
PASSPORT_OIDCAUTH_FAILURE_REDIRECT:
process.env.PASSPORT_OIDCAUTH_FAILURE_REDIRECT || "/error",
_set(key: any, value: any) { _set(key: any, value: any) {
process.env[key] = value process.env[key] = value
// @ts-ignore // @ts-ignore