angular-digest-auth
angular-digest-auth copied to clipboard
Cross Domain calls not working, every time 401 only getting even though Authorization header is added
There are 2 local sites that are running on different ports one is for server and one is UI. The server has enabled the CORS using the following settings.
1. <add name="Access-Control-Allow-Origin" value="http://localhost" />
2. <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,PATCH,OPTIONS" />
3. <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept, Authorization" />
4. <add name="Access-Control-Allow-Credentials" value="true" />
and also enabled the digest authentication in the IIS.
Now coming to the UI, i created the angular module as per the guidelines provided in the Readme file. Following is my code.
var app = angular.module("poc", ["dgAuth"]);
app.config(['dgAuthServiceProvider', function (dgAuthServiceProvider) {
dgAuthServiceProvider.setHeader('WWW-Authenticate');
dgAuthServiceProvider.setLimit('inf');
dgAuthServiceProvider.setConfig({
login: {
method: 'GET',
url: 'http://localhost:1111/api/values',
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
},
logout: {
method: 'GET',
url: 'http://localhost:1111/api/values'
}
});
dgAuthServiceProvider.callbacks.login.push(function (AuthenticationSvc) {
return {
successful: function (response) {
console.log(response);
},
error: function (response) {
console.log(response);
},
required: function (response) {
console.log(response);
},
limit: function (response) {
console.log(response);
}
};
});
dgAuthServiceProvider.callbacks.logout.push(function (AuthenticationSvc) {
return {
successful: function (response) {
console.log(response);
},
error: function (response) {
console.log(response);
}
};
});
// dgAuthServiceProvider.setStorage(localStorage);
}]);
app.controller("first", function ($scope, dgAuthService, $http) {
$scope.userName = "";
$scope.password = "";
$scope.login = function () {
dgAuthService.setCredentials($scope.userName, $scope.password);
dgAuthService.signin();
dgAuthService.isAuthorized().then(function (response) {
$http({
url: 'http://localhost:1111/api/values/get',
method: "GET",
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).then(
function (response) {
console.log(response)
},
function (response) {
console.log(response)
}
)
});
}
});
app.run(['dgAuthService', function (dgAuthService) {
/**
* It tries to sign in. If the service doesn't find
* the credentials stored or the user is not signed in yet,
* the service executes the required function.
*/
dgAuthService.start();
}]);
I am getting status as -1 in all the request errors. Getting unauthorized when checked in the browser console. Highly appreciable if any one provide the solution ASAP.
Note : I downloaded the reference files directly from the bower.