From d932671f1a071963a033e572046a3af0d0d74d08 Mon Sep 17 00:00:00 2001 From: Josh McCullough Date: Tue, 28 Jan 2020 12:32:00 -0500 Subject: [PATCH] re-apply ClaraKM SSO customization --- web-app/package.json | 1 + web-app/src/ng1/app.js | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/web-app/package.json b/web-app/package.json index 120f86e7b..a685bbfdb 100644 --- a/web-app/package.json +++ b/web-app/package.json @@ -89,6 +89,7 @@ "jquery": "^3.7.1", "jquery-file-download": "1.4.6", "jquery-minicolors": "2.1.10", + "js-cookie": "^2.2.0", "leaflet": "1.7.1", "leaflet-editable": "1.2.0", "leaflet-groupedlayercontrol": "git+https://github.com/newmanw/leaflet-groupedlayercontrol.git#master", diff --git a/web-app/src/ng1/app.js b/web-app/src/ng1/app.js index 7538940d9..a79473c4c 100644 --- a/web-app/src/ng1/app.js +++ b/web-app/src/ng1/app.js @@ -7,6 +7,7 @@ import fileBrowser from './file-upload/file.browser.component'; import uiRouter from "@uirouter/angularjs"; import { SwaggerComponent } from "../app/swagger/swagger.component"; import { downgradeComponent, downgradeInjectable } from '@angular/upgrade/static'; +import cookies from 'js-cookie'; import { MatIcon, @@ -475,9 +476,9 @@ function config($httpProvider, $locationProvider, $stateProvider, $urlRouterProv }); } -run.$inject = ['$rootScope', '$uibModal', '$state', 'Api']; +run.$inject = ['$rootScope', '$uibModal', '$state', 'Api', 'LocalStorageService', 'UserService']; -function run($rootScope, $uibModal, $state, Api) { +function run($rootScope, $uibModal, $state, Api, LocalStorageService, UserService) { $rootScope.$on('event:auth-loginRequired', function(e, response) { const stateExceptions = ['landing']; @@ -519,6 +520,19 @@ function run($rootScope, $uibModal, $state, Api) { }); } }); + + trySSO(LocalStorageService, UserService); +} + +function trySSO(LocalStorageService, UserService) { + const ssoTokenCookie = cookies.get('mage-sso-token'); + + // if SSO token exists, set it in local storage and fetch current user + if (ssoTokenCookie) { + LocalStorageService.setToken(ssoTokenCookie); + + return UserService.getMyself(); + } } export default app;