Rafael - Developer Rafael - Developer - 1 month ago 4x
AngularJS Question

Forms Authentication - token send to controller

When I send this token to Controller in WebApi I get information 401 (Unauthorized) Why? I take this token form login and it`s correct.

$scope.expiresCookie = $cookies.get('expires');
$scope.issuedCookie = $cookies.get('issued');
$scope.access_tokenCookie = $cookies.get('access_token');
$scope.expires_inCookie = $cookies.get('expires_in');
$scope.token_typeCookie = $cookies.get('token_type');
$scope.user_nameCookie = $cookies.get('user_name');

$scope.addLink = "http://localhost:56305/api/ProductInsuranceCar";

method: "GET",
url: $scope.addLink,
headers: { 'Authorization': '' + $scope.token_typeCookie + ' ' + $scope.access_tokenCookie + '' },
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}).then(function mySucces(response) {
$scope.test = response;
}, function myError(response) {

Picture 1

enter image description here

Picture 2

enter image description here

Example correct request

enter image description here

When I use Advanced Rest Client I get information but in my method :/ not working...

enter image description here


The problem could be when calling web api from a different UI domain.

Cookies are not sent if domains are different. So, If you call from localhost:64757 to localhost:56305 cookies are not sent, that's why you are receiving Unathorized 401 error.