Reputation: 7725
I have a Laravel API using Laravel Passport (OAuth2 with password grant). When I access an endpoint with Postman, it responds correctly. When I try to access with jQuery, I get this error:
Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response
Here is my jQuery code:
$.ajax({
type: 'get',
url: url,
dataType: 'json',
headers: {
'Authorization': 'Bearer ' + access_token
},
success: function(result) {
console.log(result);
},
error: function(error) {
console.log(error)
}
});
Upvotes: 1
Views: 3433
Reputation: 574
Have you checked your Laravel setup? You need to add CORS on your Laravel end.
Some usefull resources:
https://learninglaravel.net/laravel-51-easily-enable-cors
https://github.com/barryvdh/laravel-cors
Upvotes: 2