LP#1775466 Migrate auth cookies to / for sharing
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Aug 2018 14:45:17 +0000 (10:45 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 29 Aug 2018 14:48:09 +0000 (10:48 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/default/staff/services/auth.js
Open-ILS/web/js/ui/default/staff/services/hatch.js

index 9048a34..cf3b78a 100644 (file)
@@ -63,6 +63,10 @@ function($q , $timeout , $rootScope , $window , $location , egNet , egHatch) {
      * authtoken is found, otherwise rejected */
     service.testAuthToken = function() {
         var deferred = $q.defer();
+
+        // Move legacy cookies from /eg/staff to / before fetching the token.
+        egHatch.migrateAuthCookies();
+
         var token = service.token();
 
         if (token) {
index fb0ad68..31ce360 100644 (file)
@@ -352,6 +352,24 @@ angular.module('egCoreMod')
         }
     }
 
+    // Force auth cookies to live under path "/" instead of "/eg/staff"
+    // so they may be shared with the Angular app.
+    // There's no way to tell under what path a cookie is stored in
+    // the browser, all we can do is migrate it regardless.
+    service.migrateAuthCookies = function() {
+        [   'eg.auth.token', 
+            'eg.auth.time', 
+            'eg.auth.token.oc', 
+            'eg.auth.time.oc'
+        ].forEach(function(key) {
+            var val = service.getLoginSessionItem(key);
+            if (val) {
+                $cookies.remove(key, {path: '/eg/staff/'});
+                service.setLoginSessionItem(key, val);
+            }
+        });
+    }
+
     service.getLoginSessionItem = function(key) {
         var val = $cookies.get(key);
         if (val == null) return;