In this episode, we dive into the basics of handling OAuth redirects in a Laravel app—specifically setting up the flow to let users sign in through an external service like Twitter/X.
We start by building a splash screen with sign-in buttons, so users have an easy way to kick off OAuth. Then, we get Laravel Socialite installed, which is the go-to package for social authentication in Laravel.
Next up is creating and wiring up controllers for routing users correctly. We add a route that displays the new splash/login page and update the default login button to send users there instead. The splash page is styled simply with Tailwind, but the main idea is just to have a "Sign in with X" button, which starts the whole OAuth process.
We walk through setting up an app on Twitter/X, grabbing API keys and tokens, and putting those in Laravel’s configuration files (and your .env
for secrets) so Socialite can do its thing. There’s also some troubleshooting around getting the app and callback URLs right—essential when working with OAuth, since the provider needs to redirect users correctly back to your app.
Finally, we test clicking the sign-in button, which triggers redirection over to Twitter's consent screen, and then after authorizing, the user is sent right back to our app. We end the episode with a recap of all the moving pieces: the splash page, redirect controller, Socialite config, and the callback handler that you’ll use in the next episode to pull user info from Twitter.
If this is your first time setting up OAuth with Laravel, it’s a lot to take in, but just follow along and you’ll see how these building blocks connect! In the next episode, we’ll actually grab user data after the redirect and finish linking that account up in your app.