I tried to call an external API written in java spring with cors enabled from my angularjs app but i get 403 forbidden error while trying to make a request to the server.
My angularjs controller
.controller('loginCtrl', function($http, $httpParamSerializerJQLike) {
var vm = this;
$http.defaults.headers.common['Authorization'] = 'Basic ' + 'd2ViX2FwcDo='
vm.fnlogin = function(item) {
var postData = {
'username': item.email,
'password': item.password,
'grant_type': 'password'
}
$http({
url: 'http://sample.herokuapp.com/oauth/token',
method: 'POST',
data: $httpParamSerializerJQLike(postData),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function() {
})
}
})
I am getting the below errors
Failed to load resource: the server responded with a status of 403 (Forbidden)
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:51396' is therefore not allowed access. The response had HTTP status code 403
Any help will be really appreciated and i am using angular 1.6.4
P.s : If i make a request using postman then i am able to generate oauth tokens but when i call from my angular app i get error. Thanks