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: support to login the user using the token and oms found in query params #92

Merged
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
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@hotwax/dxp-components": "^1.11.0",
"@hotwax/oms-api": "^1.9.0",
"@hotwax/oms-api": "^1.13.0",
"@ionic/core": "^7.6.0",
"@ionic/vue": "^7.6.0",
"@ionic/vue-router": "^7.6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAuthStore } from "@/store/auth";

const loginGuard = (to: any, from: any, next: any) => {
const authStore = useAuthStore()
if (authStore.isAuthenticated && !to.query?.redirectUrl) {
if (authStore.isAuthenticated && !to.query?.redirectUrl && !to.query?.oms) {
next('/home')
}
next();
Expand Down
12 changes: 11 additions & 1 deletion src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
getBaseUrl: (state) => {
let baseURL = process.env.VUE_APP_BASE_URL
if (!baseURL) baseURL = state.oms
return baseURL.startsWith('http') ? baseURL : `https://${baseURL}.hotwax.io/api/`
return baseURL.startsWith('http') ? baseURL.includes('/api') ? baseURL : `${baseURL}/api/` : `https://${baseURL}.hotwax.io/api/`
},
getRedirectUrl: (state) => state.redirectUrl,
},
Expand All @@ -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 (18.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 (20.x)

Unexpected console statement
return Promise.reject(new Error(resp.data._ERROR_MESSAGE_));
}

Expand All @@ -65,7 +65,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 68 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.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 (20.x)

Unexpected console statement
return Promise.reject(new Error(error))
}
},
Expand All @@ -82,7 +82,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 85 in src/store/auth.ts

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement
return Promise.reject(new Error(error))
}
},
Expand All @@ -102,6 +102,16 @@
}
this.redirectUrl = ''
updateToken('');
},
async setToken(token: any, expirationTime: any) {
this.token = {
value: token,
expiration: expirationTime
}
updateToken(token)
},
async setCurrent(current: any) {
this.current = current
}
},
persist: true
Expand Down
45 changes: 41 additions & 4 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,19 @@
async initialise() {
this.hideBackground = true
await this.presentLoader("Processing");
// SAML login handling as only token will be returned in the query
if (this.$route.query?.token) {

// Run the basic login flow when oms and token both are found in query
if (this.$route.query?.oms && this.$route.query?.token) {
// if a session is already active, present alert
if (this.authStore.isAuthenticated) {
await this.confirmActvSessnLoginOnRedrct(true)
} else {
await this.basicLogin()
this.dismissLoader();
return;
}
} else if (this.$route.query?.token) {
// SAML login handling as only token will be returned in the query when login through SAML
await this.samlLogin()
this.dismissLoader();
return
Expand Down Expand Up @@ -221,7 +232,7 @@
this.loginOption = resp.data
}
} catch (error) {
console.error(error)

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

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement
}
},
async login() {
Expand All @@ -242,7 +253,7 @@
this.router.push('/')
}
} catch (error) {
console.error(error)

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

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement
}
},
async samlLogin() {
Expand All @@ -255,10 +266,27 @@
this.router.push('/')
}
} catch (error) {
console.error(error)

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

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement
}
},
async confirmActvSessnLoginOnRedrct() {
async basicLogin() {
try {
const { oms, token, expirationTime } = this.$route.query as any
await this.authStore.setOMS(oms);

// Setting token previous to getting user-profile, if not then the client method honors the state token
await this.authStore.setToken(token, expirationTime)

const current = await UserService.getUserProfile(token);
await this.authStore.setCurrent(current)
} catch (error) {
showToast(translate('Failed to fetch user-profile, please try again'));
console.error("error: ", error);

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

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement
}
this.router.push('/')
},
// Pass redirect as true when you want to remove all the url params when user clicks on login
async confirmActvSessnLoginOnRedrct(redirect = false) {
this.isConfirmingForActiveSession = true
const alert = await alertController
.create({
Expand All @@ -269,7 +297,11 @@
buttons: [{
text: translate('Resume'),
handler: () => {
window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}`
if(this.authStore.getRedirectUrl) {
window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}`
} else {
this.router.push('/')
}
this.isConfirmingForActiveSession = false;
}
}, {
Expand All @@ -279,6 +311,11 @@
await this.authStore.logout()
this.authStore.setRedirectUrl(redirectUrl)
this.isConfirmingForActiveSession = false;

if(redirect) {
this.basicLogin()
return;
}
}
}]
});
Expand Down
Loading