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

Implemented: saml login #22

Merged
merged 5 commits into from
Jul 28, 2023
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
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 @@ -45,7 +45,7 @@
const resp = await UserService.login(username, password);
if (hasError(resp)) {
showToast(translate('Sorry, your username or password is incorrect. Please try again.'));
console.error("error", resp.data._ERROR_MESSAGE_);

Check warning on line 48 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 48 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_));
}

Expand All @@ -65,19 +65,20 @@
// If any of the API call in try block has status code other than 2xx it will be handled in common catch block.
// TODO Check if handling of specific status codes is required.
showToast(translate('Something went wrong while login. Please contact administrator.'));
console.error("error: ", error);

Check warning on line 68 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 68 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(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 All @@ -94,7 +95,7 @@
// If any of the API call in try block has status code other than 2xx it will be handled in common catch block.
// TODO Check if handling of specific status codes is required.
showToast(translate('Something went wrong while login. Please contact administrator.'));
console.error("error: ", error);

Check warning on line 98 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 98 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(error))
}
},
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 { 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 @@
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
Loading