See if this is helpful: https://laracasts.com/discuss/channels/vue/cors-no-access-control-allow-origin-header-is-present
Laravel 8 api autorization header cors
I have an api/books endpoint that returns books in json format. (currently without authorization).
I have a vuejs mobile app that makes the axios call to the books endpoint. I receive the json with success. But as soon as I add the authorization header at the axios call I get a cors error:
'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource'.
My config/cors.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Cross-Origin Resource Sharing (CORS) Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your settings for cross-origin resource sharing
| or "CORS". This determines what cross-origin operations may execute
| in web browsers. You are free to adjust these settings as needed.
|
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
*/
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['Authorization'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
];
I can't allow an origin because it is a mobile app with a token to authenticate.
Turns out it had nothing to do with the CORS config, my server (direct admin) didn't support OPTIONS request. You can enable it like this: https://help.directadmin.com/item.php?id=700 (but also add OPTIONS after GET:DELETE.)
Please or to participate in this conversation.