From d7cdc3e7bc77fb058c50aceeab1304a987827620 Mon Sep 17 00:00:00 2001 From: deetz99 Date: Wed, 11 Dec 2024 15:37:21 -0800 Subject: [PATCH 1/3] block vertain idps from logging in --- strr-base-web/app/locales/en-CA.ts | 10 +++++++++- strr-base-web/app/middleware/auth.ts | 13 +++++++++---- strr-base-web/app/pages/auth/login.vue | 8 ++++++++ strr-host-pm-web/nuxt.config.ts | 4 ++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/strr-base-web/app/locales/en-CA.ts b/strr-base-web/app/locales/en-CA.ts index 57eb43946..edc3c0b06 100644 --- a/strr-base-web/app/locales/en-CA.ts +++ b/strr-base-web/app/locales/en-CA.ts @@ -390,7 +390,15 @@ export default { streetHint: 'Street address, PO box, rural route, or general delivery address', noAccountsFound: 'No accounts found, please click below to get started with an account.' }, - toast: {}, + toast: { + invalidIdp: { + generic: 'Invalid login source. Please login with one of the options provided.', + BCROS: '', // TODO: more specific messages ??? + IDIR: '', + BCSC: '', + BCEID: '' + } + }, feeSummary: { title: 'Fee Summary', total: 'Total Fees', diff --git a/strr-base-web/app/middleware/auth.ts b/strr-base-web/app/middleware/auth.ts index 965e621b2..291048ef3 100644 --- a/strr-base-web/app/middleware/auth.ts +++ b/strr-base-web/app/middleware/auth.ts @@ -1,8 +1,13 @@ export default defineNuxtRouteMiddleware(() => { - const { isAuthenticated } = useKeycloak() - const localePath = useLocalePath() - - if (!isAuthenticated.value) { + const { isAuthenticated, kcUser, logout } = useKeycloak() + const allowedIdps = useAppConfig().strrBaseLayer.page.login.options.idps + if (!isAuthenticated.value) { // redirect to login page if user not authenticated + const localePath = useLocalePath() return navigateTo(localePath('/auth/login')) + } else if (!allowedIdps.includes(kcUser.value.loginSource.toLowerCase())) { // log user out and redirect to login page if user authenticated with invalid login source + const locale = useNuxtApp().$i18n.locale.value + const redirectUrl = + useRuntimeConfig().public.baseUrl + locale + '/auth/login?invalidIdp=' + kcUser.value.loginSource + logout(redirectUrl) } }) diff --git a/strr-base-web/app/pages/auth/login.vue b/strr-base-web/app/pages/auth/login.vue index 70cfd40b2..8f3f87234 100644 --- a/strr-base-web/app/pages/auth/login.vue +++ b/strr-base-web/app/pages/auth/login.vue @@ -41,6 +41,14 @@ definePageMeta({ middleware: 'login-page', hideBreadcrumbs: true }) + +// show notification if user was redirected here with an invalid login +onMounted(() => { + const invalidIdp = useRoute().query.invalidIdp + if (invalidIdp && LoginSource[invalidIdp as LoginSource] !== undefined) { + useToast().add({ title: t('toast.invalidIdp.generic') }) + } +})