Laravel makes it easy to set up OAuth2 both as a server and a client. In this article, you will find resources such as tutorials and tips that will help you with your OAuth2 development work.
Whether your goal is to set up an OAuth2 server or create client code that authenticates users with a remote OAuth2 server, Laravel has just the solution for you. Well, two solutions to be precise: Laravel Passport for OAuth2 server and Laravel Socialite for OAuth2 client. For an authentication server solution that is lighter and simpler, check out Laravel Sanctum. It isn’t OAuth2, but if you’re looking for something featherweight Sanctum might interest you.
1. Official Laravel Passport Documentation
The Laravel dev team has really hit out of the park with their Laravel Passport tutorial. Everything you need to know in order to set up a functional and secure OAuth2 server using Passport is in the tutorial. That includes installation, testing, and everything in between.
Check out the tutorial here.
2. Official Laravel Socialite Documentation
Are you developing a Laravel application that needs to authenticate with an OAuth2 server? Perhaps the user will be using their Facebook or a Google account to log into the application? As of Laravel 8.x, Socialite supports authentication with Facebook, Twitter, LinkedIn, Google, GitHub, GitLab, and Bitbucket. All you need is a few lines of code, now THAT’S productivity!
Check out the tutorial here.
3. OAuth2 Overview
The official documentation/tutorials are great but what exactly is OAuth2 again? Yes, it’s an authentication method and you vaguely remember that there are some tokens involved. If you’re like me who doesn’t have the greatest memory in the world, this dev guide and overview video will help refresh your memory of OAuth2.
- Digital Ocean: An Introduction to OAuth2
- InterSystems Learning Services: OAuth 2.0: An Overview (YouTube video)
- SoapUI: OAuth2 Overview – short, concise, with easy-to-read flow chart and everybody loves flow charts.
4. Stack Overflow
Even if you follow the tutorials exactly, you might still run into errors and bugs. When that happens, nothing beats spending hours debugging the problem in silos. That’s what software developers do, amirite? Just kidding, as any experienced coder will tell you, the only correct answer is “Google the problem and click on the result that says Stack Overflow.” To save you some time, here are the links to the Stack Overflow Q & As for Passport and Socialite respectively.
- Tagged Laravel Passport on Stack Overflow
- Tagged Laravel Socialite on Stack Overflow
- Tagged Laravel on Stack Overflow
5. Video about Laravel Passport
This video by Andrew Schmelyun does a great job at covering Laravel Passport. Andrew uses Laravel 8.x in his video and refers to the official documentation a lot. The latter is a plus in my opinion because you can use both resources without conflict.
Getting started with Laravel Passport and OAuth2 – watch it here
6. Video about Laravel Socialite
Next up we have a video by Code for You. The video walks you through step-by-step on how to use Laravel Socialite to log in with Facebook and other supported platforms.
Laravel Socialite (Social Login) – Login with google, facebook and github – watch it here
Other OAuth2 & Laravel Resources
And that wraps up our collection of Laravel OAuth2 resources. Did we miss anything? Are there any articles, videos, guides, or new Laravel module that should be included in this guide? Let me know!