Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sjos's avatar
Level 1

CORS error while redirecting to Google oAuth 2.0 using Socialite

Hi, I'm trying to implement Google oAuth into my Laravel/InertiaJS application using Socialite. I've added my development url into certified urls tab in the oAuth Client ID dashboard. Also I've added two routes in my web.php file, one for redirecting to google and one for receiving the callback. However when visit the redirect route on my frontend I get the following error after redirecting to google from my server.

Access to XMLHttpRequest at 'https://accounts.google.com/o/oauth2/auth?client_id={id}.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flvh.me%2Fauth%2Fcallback&scope=openid+profile+email&response_type=code&state=MGJD1EVxDaR5j6xsqZGxEkJPazfKBenidar0onaP' (redirected from 'http://lvh.me/auth/redirect') from origin 'http://lvh.me' 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.

When I manually open the provided link in the browser I do get the Google oAuth consent screen.

Anybody know why this might be happening?

0 likes
6 replies
mrvbltzr's avatar

Use a regular <a> tag instead of Inertia's <Link> tag.

7 likes
pmattheew's avatar

@Nelwhix could you find a solution to it man? I'm facing it right now trying to implement it to my application 😐

1 like

Please or to participate in this conversation.