Improve store ui to support sso

revert-70ac1926
Vigneshan Seshamany 4 years ago
parent 0917d3bf7f
commit 6ee1d31a0e

@ -1,4 +1,5 @@
{ {
"appName": "store",
"theme": { "theme": {
"type": "default", "type": "default",
"value": "lightBaseTheme", "value": "lightBaseTheme",
@ -17,7 +18,10 @@
}, },
"loginUri": "/store-ui-request-handler/login", "loginUri": "/store-ui-request-handler/login",
"logoutUri": "/store-ui-request-handler/logout", "logoutUri": "/store-ui-request-handler/logout",
"platform": "store" "ssoLoginUri": "/store-ui-request-handler/ssoLogin",
"ssoLogoutUri": "/store-ui-request-handler/ssoLogout",
"platform": "store",
"appUiConfigUri": "/api/device-mgt-config/v1.0/configurations/ui-config"
}, },
"defaultPlatformIcons": { "defaultPlatformIcons": {
"default": { "default": {

@ -21,8 +21,9 @@ import 'antd/dist/antd.less';
import RouteWithSubRoutes from './components/RouteWithSubRoutes'; import RouteWithSubRoutes from './components/RouteWithSubRoutes';
import { BrowserRouter as Router, Redirect, Switch } from 'react-router-dom'; import { BrowserRouter as Router, Redirect, Switch } from 'react-router-dom';
import axios from 'axios'; import axios from 'axios';
import { Layout, Spin, Result } from 'antd'; import { Layout, Result, Spin } from 'antd';
import ConfigContext from './components/context/ConfigContext'; import ConfigContext from './components/context/ConfigContext';
import { getUiConfig } from './services/utils/uiConfigHandler';
const { Content } = Layout; const { Content } = Layout;
const loadingView = ( const loadingView = (
@ -138,9 +139,19 @@ class App extends React.Component {
const redirectUrl = encodeURI(window.location.href); const redirectUrl = encodeURI(window.location.href);
const pageURL = window.location.pathname; const pageURL = window.location.pathname;
const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
if (lastURLSegment !== 'login') { getUiConfig(config).then(uiConfig => {
if (uiConfig !== undefined) {
if (uiConfig.isSsoEnable) {
window.location =
window.location.origin +
config.serverConfig.ssoLoginUri +
'?redirect=' +
window.location.origin +
pageURL;
} else if (lastURLSegment !== 'login') {
window.location.href = window.location.href =
window.location.origin + `/store/login?redirect=${redirectUrl}`; window.location.origin +
`/${config.appName}/login?redirect=${redirectUrl}`;
} else { } else {
this.setState({ this.setState({
loading: false, loading: false,
@ -153,6 +164,13 @@ class App extends React.Component {
error: true, error: true,
}); });
} }
});
} else {
this.setState({
loading: false,
error: true,
});
}
}; };
render() { render() {

@ -22,6 +22,7 @@ import { Menu } from 'antd';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../services/utils/errorHandler';
import { getUiConfig } from '../../../../services/utils/uiConfigHandler';
/* /*
This class for call the logout api by sending request This class for call the logout api by sending request
@ -45,19 +46,33 @@ class Logout extends React.Component {
inValid: false, inValid: false,
}); });
let logoutUri;
getUiConfig(config).then(uiConfig => {
if (uiConfig !== undefined) {
if (uiConfig.isSsoEnable) {
logoutUri = window.location.origin + config.serverConfig.ssoLogoutUri;
} else {
logoutUri = window.location.origin + config.serverConfig.logoutUri;
}
axios axios
.post(window.location.origin + config.serverConfig.logoutUri) .post(logoutUri)
.then(res => { .then(res => {
// if the api call status is correct then user will logout and then it goes to login page // if the api call status is correct then user
// will logout and then it goes to login page
if (res.status === 200) { if (res.status === 200) {
window.location = window.location.origin + '/store/login'; window.location =
window.location.origin + `/${config.appName}/login`;
} }
}) })
.catch(function(error) { .catch(function(error) {
handleApiError( handleApiError(error, 'Error occurred while trying to logout.');
error, });
'Error occurred while trying to get your review.', } else {
); this.setState({
loading: false,
error: true,
});
}
}); });
}; };

@ -0,0 +1,40 @@
/*
* Copyright (C) 2020. Entgra (Pvt) Ltd, https://entgra.io
* All Rights Reserved.
*
* Unauthorized copying/redistribution of this file, via any medium
* is strictly prohibited.
* Proprietary and confidential.
*
* Licensed under the Entgra Commercial License,
* Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* You may obtain a copy of the License at
* https://entgra.io/licenses/entgra-commercial/1.0
*/
import axios from 'axios';
import { notification } from 'antd';
export const getUiConfig = config => {
return axios
.get(window.location.origin + config.serverConfig.appUiConfigUri)
.then(res => {
return res.data;
})
.catch(error => {
notification.error({
message: 'There was a problem',
duration: 0,
description: 'Error occurred while trying to load UI configurations.',
});
});
};
Loading…
Cancel
Save