Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid idp middleware #380

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion strr-base-web/app/locales/en-CA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 9 additions & 4 deletions strr-base-web/app/middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -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 (isAuthenticated.value && !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)
}
})
8 changes: 8 additions & 0 deletions strr-base-web/app/pages/auth/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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') })
}
})
</script>
<template>
<div class="flex grow justify-center py-10">
Expand Down
2 changes: 1 addition & 1 deletion strr-host-pm-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "strr-host-pm-web",
"private": true,
"type": "module",
"version": "0.0.3",
"version": "0.0.4",
"scripts": {
"build-check": "nuxt build",
"build": "nuxt generate",
Expand Down
2 changes: 1 addition & 1 deletion strr-platform-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "strr-platform-web",
"private": true,
"type": "module",
"version": "0.0.17",
"version": "0.0.18",
"scripts": {
"build-check": "nuxt build",
"build": "nuxt generate",
Expand Down
2 changes: 1 addition & 1 deletion strr-strata-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "strr-strata-web",
"private": true,
"type": "module",
"version": "0.0.14",
"version": "0.0.15",
"scripts": {
"build-check": "nuxt build",
"build": "nuxt generate",
Expand Down
Loading