Merge pull request #2313 from ryanpetrello/fix-ui-401

don't send WWW-Authenticate: Basic for AJAX, and properly detect 401
This commit is contained in:
Ryan Petrello
2018-06-26 10:07:35 -04:00
committed by GitHub
3 changed files with 7 additions and 2 deletions

View File

@@ -233,6 +233,8 @@ class APIView(views.APIView):
use the request header as an indication for which authentication method use the request header as an indication for which authentication method
was attempted. was attempted.
""" """
if request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest':
return 'Bearer realm=api'
for authenticator in self.get_authenticators(): for authenticator in self.get_authenticators():
try: try:
resp_hdr = authenticator.authenticate_header(request) resp_hdr = authenticator.authenticate_header(request)

View File

@@ -14,6 +14,10 @@
[ '$rootScope', '$q', '$injector', [ '$rootScope', '$q', '$injector',
function ($rootScope, $q, $injector) { function ($rootScope, $q, $injector) {
return { return {
request: function (config) {
config.headers['X-Requested-With'] = 'XMLHttpRequest';
return config;
},
response: function(config) { response: function(config) {
if(config.headers('auth-token-timeout') !== null){ if(config.headers('auth-token-timeout') !== null){
$rootScope.loginConfig.promise.then(function () { $rootScope.loginConfig.promise.then(function () {

View File

@@ -165,8 +165,7 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
Alert('Conflict', data.conflict || "Resource currently in use."); Alert('Conflict', data.conflict || "Resource currently in use.");
} else if (status === 410) { } else if (status === 410) {
Alert('Deleted Object', 'The requested object was previously deleted and can no longer be accessed.'); 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') || } else if ((status === 'Session is expired') || (status === 401)) {
(status === 401 && data && data.detail && data.detail === 'Invalid token')) {
if ($rootScope.sessionTimer) { if ($rootScope.sessionTimer) {
$rootScope.sessionTimer.expireSession('idle'); $rootScope.sessionTimer.expireSession('idle');
} }