From 541134a88f11252206483935451bcc0d776be684 Mon Sep 17 00:00:00 2001 From: sadnub Date: Sun, 15 Sep 2024 22:22:28 -0400 Subject: [PATCH 01/36] sso init --- src/boot/axios.js | 12 +- .../modals/coresettings/EditCoreSettings.vue | 8 + src/ee/sso/api/sso.ts | 97 ++++++++++ src/ee/sso/components/SSOProvidersForm.vue | 112 ++++++++++++ src/ee/sso/components/SSOProvidersTable.vue | 172 ++++++++++++++++++ src/ee/sso/types/sso.ts | 8 + src/ee/sso/utils/cookies.ts | 15 ++ src/ee/sso/views/ProviderCallback.vue | 28 +++ src/router/routes.js | 5 + src/views/LoginView.vue | 27 ++- 10 files changed, 482 insertions(+), 2 deletions(-) create mode 100644 src/ee/sso/api/sso.ts create mode 100644 src/ee/sso/components/SSOProvidersForm.vue create mode 100644 src/ee/sso/components/SSOProvidersTable.vue create mode 100644 src/ee/sso/types/sso.ts create mode 100644 src/ee/sso/utils/cookies.ts create mode 100644 src/ee/sso/views/ProviderCallback.vue diff --git a/src/boot/axios.js b/src/boot/axios.js index 9bd758bf..a57aed0e 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -22,6 +22,8 @@ export function setErrorMessage(data, message) { export default function ({ app, router }) { app.config.globalProperties.$axios = axios; + axios.defaults.withCredentials = true; + axios.interceptors.request.use( function (config) { const auth = useAuthStore(); @@ -60,7 +62,15 @@ export default function ({ app, router }) { } // unauthorized else if (error.response.status === 401) { - router.push({ path: "/expired" }); + // bypass redirect for auth check endpoint + if ( + error.config.url !== "_allauth/browser/v1/auth/session" || + error.config.url !== "ws/dashinfo" // TODO once auth is working, need to extend it to websockets + ) { + return Promise.reject({ ...error }); + } else { + router.push({ path: "/expired" }); + } } // perms else if (error.response.status === 403) { diff --git a/src/components/modals/coresettings/EditCoreSettings.vue b/src/components/modals/coresettings/EditCoreSettings.vue index 23303293..e78b90c3 100644 --- a/src/components/modals/coresettings/EditCoreSettings.vue +++ b/src/components/modals/coresettings/EditCoreSettings.vue @@ -13,6 +13,7 @@ + @@ -636,6 +637,11 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ee/sso/components/SSOProvidersTable.vue b/src/ee/sso/components/SSOProvidersTable.vue new file mode 100644 index 00000000..a5efed7d --- /dev/null +++ b/src/ee/sso/components/SSOProvidersTable.vue @@ -0,0 +1,172 @@ + + + diff --git a/src/ee/sso/types/sso.ts b/src/ee/sso/types/sso.ts new file mode 100644 index 00000000..18ad9d13 --- /dev/null +++ b/src/ee/sso/types/sso.ts @@ -0,0 +1,8 @@ +export interface SSOProvider { + id: number; + name: string; + provider_id: string; + client_id: string; + secret: string; + server_url: string; +} diff --git a/src/ee/sso/utils/cookies.ts b/src/ee/sso/utils/cookies.ts new file mode 100644 index 00000000..681d043e --- /dev/null +++ b/src/ee/sso/utils/cookies.ts @@ -0,0 +1,15 @@ +export function getCookie(name: string) { + let cookieValue = null; + if (document.cookie && document.cookie !== "") { + const cookies = document.cookie.split(";"); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === name + "=") { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; +} diff --git a/src/ee/sso/views/ProviderCallback.vue b/src/ee/sso/views/ProviderCallback.vue new file mode 100644 index 00000000..841f7b11 --- /dev/null +++ b/src/ee/sso/views/ProviderCallback.vue @@ -0,0 +1,28 @@ + + + diff --git a/src/router/routes.js b/src/router/routes.js index ae418229..7f8c9145 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -75,6 +75,11 @@ const routes = [ name: "SessionExpired", component: () => import("@/views/SessionExpired.vue"), }, + { + path: "/account/provider/callback", + name: "ProviderCallback", + component: () => import("@/ee/sso/views/ProviderCallback.vue"), + }, { path: "/:catchAll(.*)", component: () => import("@/views/NotFound.vue") }, ]; diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index 6d5fbabc..1bd448bf 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -49,7 +49,18 @@ + + + + + + {{ provider.name }} + + + + + @@ -84,10 +95,16 @@