From f6914847b92636a239843c942bf1337704c5e510 Mon Sep 17 00:00:00 2001 From: k2maan Date: Thu, 27 Jul 2023 14:44:40 +0530 Subject: [PATCH 1/4] Implemented: SAML login --- src/services/UserService.ts | 17 +++++++++++------ src/store/auth.ts | 5 +++-- src/views/Login.vue | 6 ++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/services/UserService.ts b/src/services/UserService.ts index aea7a1a..9987104 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -33,21 +33,26 @@ const getUserProfile = async (token: any): Promise => { } } -// TODO make it functional when support is there -const isSamlLoginConfigured = async (oms: any): Promise => { - return Promise.resolve(false) +const checkLoginOptions = async (oms: string): Promise => { + return {} + // TODO uncommment when support is there + // return api({ + // url: "/service/checkLoginOptions", + // method: "POST", + // data: oms + // }); } -const prepareSamlLogin = async (appUrl: any): Promise => { +const prepareSamlLogin = async (authUrl: string): Promise => { return api({ - url: `prepareSamlLogin?relaystate=${appUrl}`, + url: authUrl, method: "get", // TODO check if post or get }); } export const UserService = { getUserProfile, - isSamlLoginConfigured, + checkLoginOptions, login, prepareSamlLogin } \ No newline at end of file diff --git a/src/store/auth.ts b/src/store/auth.ts index 41d9a38..b0b7126 100644 --- a/src/store/auth.ts +++ b/src/store/auth.ts @@ -69,15 +69,16 @@ export const useAuthStore = defineStore('authStore', { return Promise.reject(new Error(error)) } }, - async prepareSamlLogin(appUrl: string) { + async prepareSamlLogin(authUrl: string) { try { - const resp = await UserService.prepareSamlLogin(appUrl); + const resp = await UserService.prepareSamlLogin(authUrl); if (hasError(resp)) { showToast(translate('Something went wrong while login. Please contact administrator')); console.error("error", resp.data._ERROR_MESSAGE_); return Promise.reject(new Error(resp.data._ERROR_MESSAGE_)); } + // update values in the state from the response this.token = { value: resp.data.token, expiration: resp.data.expirationTime diff --git a/src/views/Login.vue b/src/views/Login.vue index 59ba23a..09f3be1 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -147,9 +147,11 @@ export default defineComponent({ const instanceURL = this.instanceUrl.trim().toLowerCase(); if (!this.baseURL) this.authStore.setOMS(this.alias[instanceURL] ? this.alias[instanceURL] : instanceURL); + const loginOption = await UserService.checkLoginOptions(this.authStore.getOMS) // only perform SSO login if it is configured and redirect URL is there - if (this.authStore.getRedirectUrl && await UserService.isSamlLoginConfigured(this.authStore.getOMS)) { - this.authStore.prepareSamlLogin(this.authStore.getRedirectUrl).then(() => { + if (this.authStore.getRedirectUrl && loginOption.loginAuthType !== 'BASIC') { + const authUrl = `${loginOption.loginAuthType}?relaystate=${window.location.href}` // passing launchpad/login URL + this.authStore.prepareSamlLogin(authUrl).then(() => { window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}` }) } else { From 938ba6f3fe8e38f919e470e7aff8825ec665e3af Mon Sep 17 00:00:00 2001 From: k2maan Date: Thu, 27 Jul 2023 15:22:13 +0530 Subject: [PATCH 2/4] Added: support for checkLoginOptions --- src/services/UserService.ts | 12 +++++------- src/views/Login.vue | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/services/UserService.ts b/src/services/UserService.ts index 9987104..1ffac04 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -34,13 +34,11 @@ const getUserProfile = async (token: any): Promise => { } const checkLoginOptions = async (oms: string): Promise => { - return {} - // TODO uncommment when support is there - // return api({ - // url: "/service/checkLoginOptions", - // method: "POST", - // data: oms - // }); + return api({ + url: "/checkLoginOptions", + method: "POST", + data: oms + }); } const prepareSamlLogin = async (authUrl: string): Promise => { diff --git a/src/views/Login.vue b/src/views/Login.vue index 09f3be1..082bbb5 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -150,7 +150,7 @@ export default defineComponent({ const loginOption = await UserService.checkLoginOptions(this.authStore.getOMS) // only perform SSO login if it is configured and redirect URL is there if (this.authStore.getRedirectUrl && loginOption.loginAuthType !== 'BASIC') { - const authUrl = `${loginOption.loginAuthType}?relaystate=${window.location.href}` // passing launchpad/login URL + const authUrl = `${loginOption.loginAuthUrl}?relaystate=${window.location.href}` // passing launchpad/login URL this.authStore.prepareSamlLogin(authUrl).then(() => { window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}` }) From e6e265e944917257d06dcc2a7bad753008c553d2 Mon Sep 17 00:00:00 2001 From: k2maan Date: Fri, 28 Jul 2023 11:38:47 +0530 Subject: [PATCH 3/4] Added: handling if checkLoginOptions fails --- src/auth-util/index.ts | 1 + src/views/Login.vue | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/auth-util/index.ts b/src/auth-util/index.ts index 3635144..e6312f5 100644 --- a/src/auth-util/index.ts +++ b/src/auth-util/index.ts @@ -7,6 +7,7 @@ const confirmActiveSessionLogin = async (redirect?: boolean) => { const authStore = useAuthStore() const alert = await alertController .create({ + backdropDismiss: false, header: translate('Already active session'), message: translate(`A session for is already active for. Do you want to continue or login again?`, { partyName: authStore.current.partyName, oms: authStore.getOMS }), buttons: [{ diff --git a/src/views/Login.vue b/src/views/Login.vue index 082bbb5..e31e683 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -67,6 +67,7 @@ import { confirmActiveSessionLogin } from "@/auth-util"; import { UserService } from "@/services/UserService"; import { translate } from "@/i18n"; import { showToast } from "@/util"; +import { hasError } from "@hotwax/oms-api"; export default defineComponent({ name: "Login", @@ -147,7 +148,15 @@ export default defineComponent({ const instanceURL = this.instanceUrl.trim().toLowerCase(); if (!this.baseURL) this.authStore.setOMS(this.alias[instanceURL] ? this.alias[instanceURL] : instanceURL); - const loginOption = await UserService.checkLoginOptions(this.authStore.getOMS) + let loginOption = {} as any + // handling if API does not exist + try { + const resp = await UserService.checkLoginOptions(this.authStore.getOMS) + if (!hasError(resp)) loginOption = resp + } catch (error) { + console.error(error) + } + // only perform SSO login if it is configured and redirect URL is there if (this.authStore.getRedirectUrl && loginOption.loginAuthType !== 'BASIC') { const authUrl = `${loginOption.loginAuthUrl}?relaystate=${window.location.href}` // passing launchpad/login URL From 386d358867913ca734d12208ff77bc54a511f415 Mon Sep 17 00:00:00 2001 From: k2maan Date: Fri, 28 Jul 2023 11:42:52 +0530 Subject: [PATCH 4/4] Improved: API failure checks for checkLoginOptions --- src/views/Login.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/Login.vue b/src/views/Login.vue index e31e683..11bf7e1 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -158,7 +158,7 @@ export default defineComponent({ } // only perform SSO login if it is configured and redirect URL is there - if (this.authStore.getRedirectUrl && loginOption.loginAuthType !== 'BASIC') { + if (this.authStore.getRedirectUrl && Object.keys(loginOption).length && loginOption.loginAuthType !== 'BASIC') { const authUrl = `${loginOption.loginAuthUrl}?relaystate=${window.location.href}` // passing launchpad/login URL this.authStore.prepareSamlLogin(authUrl).then(() => { window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}`