Skip to content

Commit 09a3b9e

Browse files
committed
Use auth token when not communicating with bmcweb
Redfish backends other than OpenBMC bmcweb expect clients to authenticate using X-Auth-Token HTTP header as that's the only standard authentication method for Redfish sessions. This code falls back to using the token in case Session creation didn't result in obtaining an XSRF cookie (as should normally happen with bmcweb). Limitations: all WebSocket-based functionality can not work (JS-based NBD Virtual Media, IP KVM, SOL), page reload drops the session and requires to log in again. Tested: logging in, observing Overview and successfully logging out of an AMI MegaRAC BMC. Logging in and navigating around a bmcweb-running system which doesn't have the code to provide cookies for Session POST request (everything works as usual sans WS-based features). Change-Id: I81dc881193440d8d252dcd283b99915bd08c0c5e Signed-off-by: Paul Fertser <[email protected]>
1 parent b2acbca commit 09a3b9e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/store/api.js

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export default {
7272
spread(callback) {
7373
return Axios.spread(callback);
7474
},
75+
set_auth_token(token) {
76+
axiosInstance.defaults.headers.common['X-Auth-Token'] = token;
77+
},
7578
};
7679

7780
export const getResponseCount = (responses) => {

src/store/modules/Authentication/AuthenticanStore.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const AuthenticationStore = {
1111
xsrfCookie: Cookies.get('XSRF-TOKEN'),
1212
isAuthenticatedCookie: Cookies.get('IsAuthenticated'),
1313
sessionURI: localStorage.getItem('sessionURI'),
14+
xAuthToken: null,
1415
},
1516
getters: {
1617
consoleWindow: (state) => state.consoleWindow,
@@ -19,31 +20,43 @@ const AuthenticationStore = {
1920
// We might have gotten XSRF-TOKEN (and HttpOnly SESSION cookie) by Mutual TLS authentication,
2021
// without going through explicit Session creation
2122
return (
22-
state.xsrfCookie !== undefined || state.isAuthenticatedCookie == 'true'
23+
state.xsrfCookie !== undefined ||
24+
state.isAuthenticatedCookie == 'true' ||
25+
state.xAuthToken !== null
2326
);
2427
},
2528
// Used to authenticate WebSocket connections via subprotocol value
2629
token: (state) => state.xsrfCookie,
2730
},
2831
mutations: {
29-
authSuccess(state, { session }) {
32+
authSuccess(state, { session, token }) {
3033
state.authError = false;
3134
state.xsrfCookie = Cookies.get('XSRF-TOKEN');
3235
// Preserve session data across page reloads and browser restarts
3336
localStorage.setItem('sessionURI', session);
3437
state.sessionURI = session;
38+
// If we didn't get the XSRF cookie it means we are talking to a
39+
// Redfish implementation that is not bmcweb. In this case get the token
40+
// from headers and send it with the future requests, do not permanently
41+
// save anywhere.
42+
if (state.xsrfCookie === undefined) {
43+
api.set_auth_token(token);
44+
state.xAuthToken = token;
45+
}
3546
},
3647
authError(state, authError = true) {
3748
state.authError = authError;
3849
},
3950
logout(state) {
4051
Cookies.remove('XSRF-TOKEN');
4152
Cookies.remove('IsAuthenticated');
53+
api.set_auth_token(undefined);
4254
localStorage.removeItem('storedUsername');
4355
state.xsrfCookie = undefined;
4456
state.isAuthenticatedCookie = undefined;
4557
localStorage.removeItem('sessionURI');
4658
state.sessionURI = null;
59+
state.xAuthToken = null;
4760
state.consoleWindow = false;
4861
},
4962
},
@@ -58,6 +71,7 @@ const AuthenticationStore = {
5871
.then((response) => {
5972
commit('authSuccess', {
6073
session: response.headers['location'],
74+
token: response.headers['x-auth-token'],
6175
});
6276
return isPasswordExpired(response);
6377
})

0 commit comments

Comments
 (0)