Skip to content

Commit

Permalink
Merge pull request #22 from k2maan/saml-login
Browse files Browse the repository at this point in the history
Implemented: saml login
  • Loading branch information
adityasharma7 authored Jul 28, 2023
2 parents 69f2d57 + 386d358 commit d877c4c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/auth-util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down
15 changes: 9 additions & 6 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ const getUserProfile = async (token: any): Promise<any> => {
}
}

// TODO make it functional when support is there
const isSamlLoginConfigured = async (oms: any): Promise<any> => {
return Promise.resolve(false)
const checkLoginOptions = async (oms: string): Promise<any> => {
return api({
url: "/checkLoginOptions",
method: "POST",
data: oms
});
}

const prepareSamlLogin = async (appUrl: any): Promise<any> => {
const prepareSamlLogin = async (authUrl: string): Promise<any> => {
return api({
url: `prepareSamlLogin?relaystate=${appUrl}`,
url: authUrl,
method: "get", // TODO check if post or get
});
}

export const UserService = {
getUserProfile,
isSamlLoginConfigured,
checkLoginOptions,
login,
prepareSamlLogin
}
5 changes: 3 additions & 2 deletions src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

Check warning on line 77 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (14.x)

Unexpected console statement

Check warning on line 77 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (16.x)

Unexpected console statement
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
Expand Down
15 changes: 13 additions & 2 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -147,9 +148,19 @@ export default defineComponent({
const instanceURL = this.instanceUrl.trim().toLowerCase();
if (!this.baseURL) this.authStore.setOMS(this.alias[instanceURL] ? this.alias[instanceURL] : instanceURL);
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)

Check warning on line 157 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (14.x)

Unexpected console statement

Check warning on line 157 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (16.x)

Unexpected console statement
}
// 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 && 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}`
})
} else {
Expand Down

0 comments on commit d877c4c

Please sign in to comment.