summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/store/modules/Authentication/AuthenticanStore.js34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js
index 2006661b..3ad41c6b 100644
--- a/src/store/modules/Authentication/AuthenticanStore.js
+++ b/src/store/modules/Authentication/AuthenticanStore.js
@@ -10,21 +10,28 @@ const AuthenticationStore = {
authError: false,
xsrfCookie: Cookies.get('XSRF-TOKEN'),
isAuthenticatedCookie: Cookies.get('IsAuthenticated'),
+ sessionURI: localStorage.getItem('sessionURI'),
},
getters: {
consoleWindow: (state) => state.consoleWindow,
authError: (state) => state.authError,
isLoggedIn: (state) => {
+ // We might have gotten XSRF-TOKEN (and HttpOnly SESSION cookie) by Mutual TLS authentication,
+ // without going through explicit Session creation
return (
state.xsrfCookie !== undefined || state.isAuthenticatedCookie == 'true'
);
},
+ // Used to authenticate WebSocket connections via subprotocol value
token: (state) => state.xsrfCookie,
},
mutations: {
- authSuccess(state) {
+ authSuccess(state, { session }) {
state.authError = false;
state.xsrfCookie = Cookies.get('XSRF-TOKEN');
+ // Preserve session data across page reloads and browser restarts
+ localStorage.setItem('sessionURI', session);
+ state.sessionURI = session;
},
authError(state, authError = true) {
state.authError = authError;
@@ -35,30 +42,33 @@ const AuthenticationStore = {
localStorage.removeItem('storedUsername');
state.xsrfCookie = undefined;
state.isAuthenticatedCookie = undefined;
+ localStorage.removeItem('sessionURI');
+ state.sessionURI = null;
+ state.consoleWindow = false;
},
- setConsoleWindow: (state, window) => (state.consoleWindow = window),
},
actions: {
login({ commit }, { username, password }) {
commit('authError', false);
return api
- .post('/login', {
- username: username,
- password: password,
+ .post('/redfish/v1/SessionService/Sessions', {
+ UserName: username,
+ Password: password,
+ })
+ .then((response) => {
+ commit('authSuccess', {
+ session: response.headers['location'],
+ });
})
- .then(() => commit('authSuccess'))
.catch((error) => {
commit('authError');
throw new Error(error);
});
},
- logout({ commit }) {
+ logout({ commit, state }) {
api
- .post('/logout', { data: [] })
- .then(() => {
- commit('setConsoleWindow', false);
- commit('logout');
- })
+ .delete(state.sessionURI)
+ .then(() => commit('logout'))
.then(() => router.push('/login'))
.catch((error) => console.log(error));
},