From 6ca2009ba0f261f69c74587ccf3d1f5a63b17f1f Mon Sep 17 00:00:00 2001 From: Brian Bolton Date: Wed, 21 Dec 2016 15:20:58 -0600 Subject: [PATCH 1/6] viinetwork/i#4085 Skip http auth interceptor if incoming 401/sso redirect --- src/http-auth-interceptor.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/http-auth-interceptor.js b/src/http-auth-interceptor.js index 060d8f8..a42e9b8 100644 --- a/src/http-auth-interceptor.js +++ b/src/http-auth-interceptor.js @@ -52,8 +52,11 @@ $httpProvider.interceptors.push(['$rootScope', '$q', 'httpBuffer', function($rootScope, $q, httpBuffer) { return { responseError: function(rejection) { - var config = rejection.config || {}; - if (!config.ignoreAuthModule) { + var config = rejection.config || {}, + meta = rejection.data.meta || {}, + redirect = meta.redirect || ''; + + if (!config.ignoreAuthModule && !(/\/sso\//.test(redirect))) { switch (rejection.status) { case 401: var deferred = $q.defer(); From d8f9b465f5d2cad18669026614a33b99f8033417 Mon Sep 17 00:00:00 2001 From: Brian Bolton Date: Wed, 21 Dec 2016 15:22:44 -0600 Subject: [PATCH 2/6] Build last commit --- dist/http-auth-interceptor.js | 7 +++++-- dist/http-auth-interceptor.min.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dist/http-auth-interceptor.js b/dist/http-auth-interceptor.js index 060d8f8..a42e9b8 100644 --- a/dist/http-auth-interceptor.js +++ b/dist/http-auth-interceptor.js @@ -52,8 +52,11 @@ $httpProvider.interceptors.push(['$rootScope', '$q', 'httpBuffer', function($rootScope, $q, httpBuffer) { return { responseError: function(rejection) { - var config = rejection.config || {}; - if (!config.ignoreAuthModule) { + var config = rejection.config || {}, + meta = rejection.data.meta || {}, + redirect = meta.redirect || ''; + + if (!config.ignoreAuthModule && !(/\/sso\//.test(redirect))) { switch (rejection.status) { case 401: var deferred = $q.defer(); diff --git a/dist/http-auth-interceptor.min.js b/dist/http-auth-interceptor.min.js index 167529a..fdd2f26 100644 --- a/dist/http-auth-interceptor.min.js +++ b/dist/http-auth-interceptor.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("http-auth-interceptor",["http-auth-interceptor-buffer"]).factory("authService",["$rootScope","httpBuffer",function($rootScope,httpBuffer){return{loginConfirmed:function(data,configUpdater){var updater=configUpdater||function(config){return config};$rootScope.$broadcast("event:auth-loginConfirmed",data),httpBuffer.retryAll(updater)},loginCancelled:function(data,reason){httpBuffer.rejectAll(reason),$rootScope.$broadcast("event:auth-loginCancelled",data)}}}]).config(["$httpProvider",function($httpProvider){$httpProvider.interceptors.push(["$rootScope","$q","httpBuffer",function($rootScope,$q,httpBuffer){return{responseError:function(rejection){var config=rejection.config||{};if(!config.ignoreAuthModule)switch(rejection.status){case 401:var deferred=$q.defer(),bufferLength=httpBuffer.append(config,deferred);return 1===bufferLength&&$rootScope.$broadcast("event:auth-loginRequired",rejection),deferred.promise;case 403:$rootScope.$broadcast("event:auth-forbidden",rejection)}return $q.reject(rejection)}}}])}]),angular.module("http-auth-interceptor-buffer",[]).factory("httpBuffer",["$injector",function($injector){function retryHttpRequest(config,deferred){function successCallback(response){deferred.resolve(response)}function errorCallback(response){deferred.reject(response)}$http=$http||$injector.get("$http"),$http(config).then(successCallback,errorCallback)}var $http,buffer=[];return{append:function(config,deferred){return buffer.push({config:config,deferred:deferred})},rejectAll:function(reason){if(reason)for(var i=0;i Date: Wed, 21 Dec 2016 15:33:21 -0600 Subject: [PATCH 3/6] fix data not defined --- dist/http-auth-interceptor.js | 1 + dist/http-auth-interceptor.min.js | 2 +- src/http-auth-interceptor.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/http-auth-interceptor.js b/dist/http-auth-interceptor.js index a42e9b8..ffa3f5f 100644 --- a/dist/http-auth-interceptor.js +++ b/dist/http-auth-interceptor.js @@ -53,6 +53,7 @@ return { responseError: function(rejection) { var config = rejection.config || {}, + data = rejection.data || {}, meta = rejection.data.meta || {}, redirect = meta.redirect || ''; diff --git a/dist/http-auth-interceptor.min.js b/dist/http-auth-interceptor.min.js index fdd2f26..c50d635 100644 --- a/dist/http-auth-interceptor.min.js +++ b/dist/http-auth-interceptor.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("http-auth-interceptor",["http-auth-interceptor-buffer"]).factory("authService",["$rootScope","httpBuffer",function($rootScope,httpBuffer){return{loginConfirmed:function(data,configUpdater){var updater=configUpdater||function(config){return config};$rootScope.$broadcast("event:auth-loginConfirmed",data),httpBuffer.retryAll(updater)},loginCancelled:function(data,reason){httpBuffer.rejectAll(reason),$rootScope.$broadcast("event:auth-loginCancelled",data)}}}]).config(["$httpProvider",function($httpProvider){$httpProvider.interceptors.push(["$rootScope","$q","httpBuffer",function($rootScope,$q,httpBuffer){return{responseError:function(rejection){var config=rejection.config||{},meta=rejection.data.meta||{},redirect=meta.redirect||"";if(!config.ignoreAuthModule&&!/\/sso\//.test(redirect))switch(rejection.status){case 401:var deferred=$q.defer(),bufferLength=httpBuffer.append(config,deferred);return 1===bufferLength&&$rootScope.$broadcast("event:auth-loginRequired",rejection),deferred.promise;case 403:$rootScope.$broadcast("event:auth-forbidden",rejection)}return $q.reject(rejection)}}}])}]),angular.module("http-auth-interceptor-buffer",[]).factory("httpBuffer",["$injector",function($injector){function retryHttpRequest(config,deferred){function successCallback(response){deferred.resolve(response)}function errorCallback(response){deferred.reject(response)}$http=$http||$injector.get("$http"),$http(config).then(successCallback,errorCallback)}var $http,buffer=[];return{append:function(config,deferred){return buffer.push({config:config,deferred:deferred})},rejectAll:function(reason){if(reason)for(var i=0;i Date: Tue, 27 Dec 2016 16:26:31 -0500 Subject: [PATCH 4/6] Fix stupid logic error --- src/http-auth-interceptor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http-auth-interceptor.js b/src/http-auth-interceptor.js index ffa3f5f..dbbe72c 100644 --- a/src/http-auth-interceptor.js +++ b/src/http-auth-interceptor.js @@ -54,7 +54,7 @@ responseError: function(rejection) { var config = rejection.config || {}, data = rejection.data || {}, - meta = rejection.data.meta || {}, + meta = data.meta || {}, redirect = meta.redirect || ''; if (!config.ignoreAuthModule && !(/\/sso\//.test(redirect))) { From a57465e1421a64211ba3982d1bb102cea6a79bab Mon Sep 17 00:00:00 2001 From: Brian Bolton Date: Tue, 27 Dec 2016 16:28:11 -0500 Subject: [PATCH 5/6] And build it... --- dist/http-auth-interceptor.js | 2 +- dist/http-auth-interceptor.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/http-auth-interceptor.js b/dist/http-auth-interceptor.js index ffa3f5f..dbbe72c 100644 --- a/dist/http-auth-interceptor.js +++ b/dist/http-auth-interceptor.js @@ -54,7 +54,7 @@ responseError: function(rejection) { var config = rejection.config || {}, data = rejection.data || {}, - meta = rejection.data.meta || {}, + meta = data.meta || {}, redirect = meta.redirect || ''; if (!config.ignoreAuthModule && !(/\/sso\//.test(redirect))) { diff --git a/dist/http-auth-interceptor.min.js b/dist/http-auth-interceptor.min.js index c50d635..28b2d8b 100644 --- a/dist/http-auth-interceptor.min.js +++ b/dist/http-auth-interceptor.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("http-auth-interceptor",["http-auth-interceptor-buffer"]).factory("authService",["$rootScope","httpBuffer",function($rootScope,httpBuffer){return{loginConfirmed:function(data,configUpdater){var updater=configUpdater||function(config){return config};$rootScope.$broadcast("event:auth-loginConfirmed",data),httpBuffer.retryAll(updater)},loginCancelled:function(data,reason){httpBuffer.rejectAll(reason),$rootScope.$broadcast("event:auth-loginCancelled",data)}}}]).config(["$httpProvider",function($httpProvider){$httpProvider.interceptors.push(["$rootScope","$q","httpBuffer",function($rootScope,$q,httpBuffer){return{responseError:function(rejection){var config=rejection.config||{},meta=(rejection.data||{},rejection.data.meta||{}),redirect=meta.redirect||"";if(!config.ignoreAuthModule&&!/\/sso\//.test(redirect))switch(rejection.status){case 401:var deferred=$q.defer(),bufferLength=httpBuffer.append(config,deferred);return 1===bufferLength&&$rootScope.$broadcast("event:auth-loginRequired",rejection),deferred.promise;case 403:$rootScope.$broadcast("event:auth-forbidden",rejection)}return $q.reject(rejection)}}}])}]),angular.module("http-auth-interceptor-buffer",[]).factory("httpBuffer",["$injector",function($injector){function retryHttpRequest(config,deferred){function successCallback(response){deferred.resolve(response)}function errorCallback(response){deferred.reject(response)}$http=$http||$injector.get("$http"),$http(config).then(successCallback,errorCallback)}var $http,buffer=[];return{append:function(config,deferred){return buffer.push({config:config,deferred:deferred})},rejectAll:function(reason){if(reason)for(var i=0;i Date: Wed, 28 Dec 2016 14:32:01 -0500 Subject: [PATCH 6/6] viinetwork/i#4085 If SSO is enabled we still need to build the retry stack in case we're doing a local login --- dist/http-auth-interceptor.js | 9 ++++++--- dist/http-auth-interceptor.min.js | 2 +- src/http-auth-interceptor.js | 9 ++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/dist/http-auth-interceptor.js b/dist/http-auth-interceptor.js index dbbe72c..7a8ea63 100644 --- a/dist/http-auth-interceptor.js +++ b/dist/http-auth-interceptor.js @@ -57,13 +57,16 @@ meta = data.meta || {}, redirect = meta.redirect || ''; - if (!config.ignoreAuthModule && !(/\/sso\//.test(redirect))) { + if (!config.ignoreAuthModule) { switch (rejection.status) { case 401: var deferred = $q.defer(); var bufferLength = httpBuffer.append(config, deferred); - if (bufferLength === 1) - $rootScope.$broadcast('event:auth-loginRequired', rejection); + if (bufferLength === 1) { + if (!(/\/sso\//.test(redirect))) { + $rootScope.$broadcast('event:auth-loginRequired', rejection); + } + } return deferred.promise; case 403: $rootScope.$broadcast('event:auth-forbidden', rejection); diff --git a/dist/http-auth-interceptor.min.js b/dist/http-auth-interceptor.min.js index 28b2d8b..de39d87 100644 --- a/dist/http-auth-interceptor.min.js +++ b/dist/http-auth-interceptor.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("http-auth-interceptor",["http-auth-interceptor-buffer"]).factory("authService",["$rootScope","httpBuffer",function($rootScope,httpBuffer){return{loginConfirmed:function(data,configUpdater){var updater=configUpdater||function(config){return config};$rootScope.$broadcast("event:auth-loginConfirmed",data),httpBuffer.retryAll(updater)},loginCancelled:function(data,reason){httpBuffer.rejectAll(reason),$rootScope.$broadcast("event:auth-loginCancelled",data)}}}]).config(["$httpProvider",function($httpProvider){$httpProvider.interceptors.push(["$rootScope","$q","httpBuffer",function($rootScope,$q,httpBuffer){return{responseError:function(rejection){var config=rejection.config||{},data=rejection.data||{},meta=data.meta||{},redirect=meta.redirect||"";if(!config.ignoreAuthModule&&!/\/sso\//.test(redirect))switch(rejection.status){case 401:var deferred=$q.defer(),bufferLength=httpBuffer.append(config,deferred);return 1===bufferLength&&$rootScope.$broadcast("event:auth-loginRequired",rejection),deferred.promise;case 403:$rootScope.$broadcast("event:auth-forbidden",rejection)}return $q.reject(rejection)}}}])}]),angular.module("http-auth-interceptor-buffer",[]).factory("httpBuffer",["$injector",function($injector){function retryHttpRequest(config,deferred){function successCallback(response){deferred.resolve(response)}function errorCallback(response){deferred.reject(response)}$http=$http||$injector.get("$http"),$http(config).then(successCallback,errorCallback)}var $http,buffer=[];return{append:function(config,deferred){return buffer.push({config:config,deferred:deferred})},rejectAll:function(reason){if(reason)for(var i=0;i