LP#1755258 Browser client auth proxy login support
authorBill Erickson <berickxx@gmail.com>
Tue, 12 Jun 2018 16:02:02 +0000 (12:02 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 5 Sep 2018 21:59:19 +0000 (17:59 -0400)
Check if the auth_proxy service is enabled during login and use the
proxy login API when it's available, otherwise fall back to standard
Evergreen open-ils.auth login.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/web/js/ui/default/staff/services/auth.js

index 9048a34..c46e37e 100644 (file)
@@ -169,7 +169,6 @@ function($q , $timeout , $rootScope , $window , $location , egNet , egHatch) {
         }
 
         service.login_api(args).then(function(evt) {
-
             if (evt.textcode == 'SUCCESS') {
                 service.handle_login_ok(args, evt);
                 ops.deferred.resolve({
@@ -240,7 +239,13 @@ function($q , $timeout , $rootScope , $window , $location , egNet , egHatch) {
         return service.testAuthToken();
     }
 
-    service.login_api = function(args) {
+    service.login_via_auth_proxy = function(args) {
+        return egNet.request(
+            'open-ils.auth_proxy',
+            'open-ils.auth_proxy.login', args);
+    }
+
+    service.login_via_auth = function(args) {
         return egNet.request(
             'open-ils.auth',
             'open-ils.auth.authenticate.init', args.username)
@@ -257,6 +262,27 @@ function($q , $timeout , $rootScope , $window , $location , egNet , egHatch) {
         );
     }
 
+    service.login_api = function(args) {
+
+        return egNet.request(
+            'open-ils.auth_proxy',
+            'open-ils.auth_proxy.enabled')
+        .then(
+            function(enabled) {
+                console.log('proxy check returned ' + enabled);
+                if (Number(enabled) === 1) {
+                    return service.login_via_auth_proxy(args);
+                } else {
+                    return service.login_via_auth(args);
+                }
+            },
+            function() {
+                // request failed, likely a result of auth_proxy not running.
+               return service.login_via_auth(args);
+            }
+        );
+    }
+
     service.handle_login_ok = function(args, evt) {
         service.ws = args.workstation; 
         egHatch.setLoginSessionItem('eg.auth.token', evt.payload.authtoken);