Laravel Inertia, CORS with google login - laravel

am using ziggy with laravel and inertia, now using google login, i get the following error:
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.
here is my laravel routes:
Route::get('auth/{provider}', 'Auth\LoginController#redirectToProvider')
->name('login.provider');
Route::get('auth/{provider}/callback', 'Auth\LoginController#handleProviderCallback')
->name('login.callback');
how would i solve it please?

The response from the google service is missing the header Access-Control-Allow-Origin: * so the browser is blocking it.
Try to research a way to have that header included in the response.

Related

How to Solve cross origin domain access error on laravel and vue js

I am creating an app with larvel and vue js. It is in two separate directories. one is larvel and vue js and the other is vue. I am trying to access some apis from vue.js directory located at the second directory. On local it was working fine but on go daddy server it says:
Chrome:
Access to XMLHttpRequest at 'https://maindirectory(larvel)' from origin 'https://(second directory)vue.js' 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.
On Firefox it says:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://directory1/api/seller/login. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 403.
I have tried almost every solution available on the internet:
i have placed these headers:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Authorization, Content-Type, X-Authorization,X-CSRF-Token,api_token');
header('Access-Control-Expose-Headers: X-Authorization, Authorization');
header('Access-Control-Allow-Methods:POST, GET, OPTIONS, PUT, DELETE');
In routes.php , api.php
and also tried setting headers in web.config and .htaccess.
But nothing helped. I have been stuck for four days. Any help would be appreciated.

Laravel + Vue - CORS errors

I am developing a Laravel API + Vue.js frontend app. Those 2 projects are on separate servers. I am having a CORS policy problem in production (on local I had, but I managed to fix it).
So basically, there are 2 errors right now. I am having this error:
Access to XMLHttpRequest at '--Laravel url--' from origin '--Vue url--' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
While my co-worker is getting this error:
Access to XMLHttpRequest at '--Laravel url--' from origin '--Vue url--' 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.
We tried a few things:
Configurating CORS on Laravel side:
setting CORS middleware - no effect
changing CORS config .php file - no effect
Configurating CORS on Vue side:
adding origin header to form - no effect
The response is also displaying in browser as being same-site although it is not.
Anyone can help? We have been searching for answer for nearly 3 days.
As Jazerix answered in a comment, going Sanctum is probably the right way because it has most stuff prepared.

aimeos jsonapi request blocked by CORS policy

On local development I am facing following error on ajax request:
Access to XMLHttpRequest at 'http://pmb.local/jsonapi/product' from origin 'http://localhost:3000' 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.
Need to the following change this this file
Ddont forget to run:
php artisan optimize

CORS Issue on iframe to current Laravel route

I am pulling in an Iframe that has javascript included in it. I have installed the fruitcake cors package and set the config file to be wide open. I also added the "Access-Control-Allow-Origin' header to the xmlhttp request just in case because I am confused on who is actually denying the request. Here is the error I am getting -
Access to XMLHttpRequest at "https://site-that-i-am-posting-to" from origin "https://where-the-iframe-is-sourced-from" has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present of the requested resource.
Figured it out. I needed to add the correct request headers to the xmlhttprequest like this -
xhrapi.setRequestHeader('Origin', 'https://site-posting-from.com');
xhrapi.setRequestHeader('Access-Control-Request-Method', 'POST');
And then it worked. Thanks to anyone that tried to help!

API Gateway: Can't Enable CORS

I can't Enable CORS on my API Gateway instance, this is how it looks:
1. Settings:
2. Result:
I've tried a bunch of things like checking the DEFAULT 4XX and DEFAULT 5XX and manually inputting the Access-Control-Allow-Methods as suggested in some posts.
If I hover over the error I get: Invalid Response status code specified.
I'm able to GET using my browser but POST can only be done from Postman. My ReactJS website won't post either, throwing:
Access to XMLHttpRequest at <ENDPOINT> from origin <S3-REACT-BUCKET> has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I've read that I have my React app should send the CORS headers (haven't got to that) but I can't even Enable CORS in the API Gateway!
That was because No Method Response
You shouldn't manually go on the console to enable CORS. Instead follow this guide from the serverless framework.
In short:
set cors: true in your http event
return {'Access-Control-Allow-Origin': '*','Access-Control-Allow-Credentials': true} in your handler

Resources