diff --git a/awx/api/generics.py b/awx/api/generics.py index 114875ad16..8505275f83 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -233,6 +233,8 @@ class APIView(views.APIView): use the request header as an indication for which authentication method was attempted. """ + if request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest': + return 'Bearer realm=api' for authenticator in self.get_authenticators(): try: resp_hdr = authenticator.authenticate_header(request) diff --git a/awx/ui/client/src/rest/interceptors.service.js b/awx/ui/client/src/rest/interceptors.service.js index e30b1d5b99..0671702e88 100644 --- a/awx/ui/client/src/rest/interceptors.service.js +++ b/awx/ui/client/src/rest/interceptors.service.js @@ -14,6 +14,10 @@ [ '$rootScope', '$q', '$injector', function ($rootScope, $q, $injector) { return { + request: function (config) { + config.headers['X-Requested-With'] = 'XMLHttpRequest'; + return config; + }, response: function(config) { if(config.headers('auth-token-timeout') !== null){ $rootScope.loginConfig.promise.then(function () { diff --git a/awx/ui/client/src/shared/Utilities.js b/awx/ui/client/src/shared/Utilities.js index b0f273c320..fdfb0a118e 100644 --- a/awx/ui/client/src/shared/Utilities.js +++ b/awx/ui/client/src/shared/Utilities.js @@ -165,8 +165,7 @@ angular.module('Utilities', ['RestServices', 'Utilities']) Alert('Conflict', data.conflict || "Resource currently in use."); } else if (status === 410) { Alert('Deleted Object', 'The requested object was previously deleted and can no longer be accessed.'); - } else if ((status === 'Session is expired') || (status === 401 && data.detail && data.detail === 'Token is expired') || - (status === 401 && data && data.detail && data.detail === 'Invalid token')) { + } else if ((status === 'Session is expired') || (status === 401)) { if ($rootScope.sessionTimer) { $rootScope.sessionTimer.expireSession('idle'); }