diff --git a/SAS/TMSS/frontend/tmss_webapp/src/authenticate/auth.js b/SAS/TMSS/frontend/tmss_webapp/src/authenticate/auth.js index fd9e89a35cedeccbb53c67ac1d5103eb21b121f7..1248708029c029ca3e97255c9fe83434c6bfc690 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/authenticate/auth.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/authenticate/auth.js @@ -9,7 +9,7 @@ const axios = require('axios'); const Auth = { /** To check if user already logged in * - First it will check the API token is available in the browser local storage - * - If not then check the Keycloak authendication + * - If not then check the Keycloak authentication * - Return false if no authentication found */ isAuthenticated: async () => { @@ -19,7 +19,7 @@ const Auth = { return Auth.getUserPermission(user); } else { //Keycloak authendication - const res = await AuthService.keycloakAuthenticate(); + const res = await AuthService.getKeycloakAuthState(); if (res && res.is_authenticated) { localStorage.setItem("loginType", 'Keycloak'); const cookies = document.cookie.split(';').reduce((prev, current) => { diff --git a/SAS/TMSS/frontend/tmss_webapp/src/authenticate/login.js b/SAS/TMSS/frontend/tmss_webapp/src/authenticate/login.js index a7fdb5d9ef7bea8594560e06cb22e7a5b2f46b26..4fd83dc7e7e788d442714c3fd71b5732fee24dda 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/authenticate/login.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/authenticate/login.js @@ -9,6 +9,9 @@ import UIConstants from '../utils/ui.constants'; * Component to authenticate users in the application. */ export class Login extends Component { + KEYCLOAK_AUTH_URL= '/oidc/authenticate/'; + REQUEST_ACCESS_URL= 'https://support.astron.nl/confluence/display/public/TMSS+User+Documentation#TMSSUserDocumentation-Requestaccess'; + FORGET_PASSWORD_URL= 'https://webportal.astron.nl/pwm/private/Login'; constructor(props){ super(props); this.state = { @@ -80,21 +83,21 @@ export class Login extends Component { * @param {*} */ async doKeyCloakLogin(e) { - window.location.href = UIConstants.KEYCLOAK_AUTH_URL; + window.location.href = this.KEYCLOAK_AUTH_URL; } /** * Redirect to forget password page */ async forgetPassword() { - window.location.href = UIConstants.FORGET_PASSWORD_URL; + window.location.href = this.FORGET_PASSWORD_URL; } /** * Redirect to Request access page */ async requestAccess() { - window.location.href = UIConstants.REQUEST_ACCESS_URL; + window.location.href = this.REQUEST_ACCESS_URL; } render() { diff --git a/SAS/TMSS/frontend/tmss_webapp/src/services/auth.service.js b/SAS/TMSS/frontend/tmss_webapp/src/services/auth.service.js index 7565cda27e2a0a25b13df1c792fed3ab155351ce..aa09a9c890d9f6765d8b1af12553d10b26f92c6f 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/services/auth.service.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/services/auth.service.js @@ -1,5 +1,3 @@ -import UIConstants from '../utils/ui.constants'; - const axios = require('axios'); const AuthService = { @@ -14,13 +12,17 @@ const AuthService = { return null; } }, - keycloakAuthenticate: async() => { + /** + * Get keycloak auth state + * @returns auth state in JSON + */ + getKeycloakAuthState: async() => { try { delete axios.defaults.headers.common['Authorization']; - const response = await axios.get(UIConstants.KEYCLOAK_AUTHENTICATE_URL); + const response = await axios.get('/api/authentication_state/'); return response.data; } catch(error) { - console.error('Error [keycloakAuthenticate]',error); + console.error('Error [getKeycloakAuthState]',error); return null; } }, @@ -45,7 +47,7 @@ const AuthService = { } contentType = axios.defaults.headers.common['Content-Type']; const formData = 'csrfmiddlewaretoken='+token; - await axios.post(UIConstants.KEYCLOAK_LOGOUT_URL, formData, {headers: { + await axios.post('/oidc/logout/', formData, {headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', }}); } diff --git a/SAS/TMSS/frontend/tmss_webapp/src/utils/ui.constants.js b/SAS/TMSS/frontend/tmss_webapp/src/utils/ui.constants.js index 102a7d724c58fc69626f50995322a87054751b85..d89aadf99a448db85546f15d0ffec2b6ec8272b0 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/utils/ui.constants.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/utils/ui.constants.js @@ -1,9 +1,4 @@ const UIConstants = { - KEYCLOAK_AUTH_URL: '/oidc/authenticate/', - KEYCLOAK_LOGOUT_URL: '/oidc/logout/', - KEYCLOAK_AUTHENTICATE_URL: '/api/authentication_state/', - REQUEST_ACCESS_URL: 'https://support.astron.nl/confluence/display/public/TMSS+User+Documentation#TMSSUserDocumentation-Requestaccess', - FORGET_PASSWORD_URL: 'https://webportal.astron.nl/pwm/private/Login', tooltipOptions: {position: 'left', event: 'hover', className:"p-tooltip-custom"}, timeline: { types: { NORMAL: "NORMAL", WEEKVIEW:"WEEKVIEW"}