Three ways to using Laravel Socialite

Taufan Fadhilah Iskandar
3 min readJun 26, 2020
Photo by Austin Distel on Unsplash

Hi folks, in this story i just want to share my result after doing some experiments to using Laravel Socialite with several conditions. Basically we know authentication is a gate for our application to access some authorized feature inside. The manual authentication flow is we need email/username and password as credential, But time by time the flow was changes. Mostly we are using social media as part of our authentication module which we can get credential from them. Laravel Socialite come to be solution for this part and makes authentication with social media easier.

In addition to typical, form based authentication, Laravel also provides a simple, convenient way to authenticate with OAuth providers using Laravel Socialite. Socialite currently supports authentication with Facebook, Twitter, LinkedIn, Google, GitHub, GitLab and Bitbucket.

About 3 years im using Socialite, i was found 3 kinds of authentication flow with social media. There are :
1. Authentication with social media on same website (monolith website)
2. Authentication with social media on website with REST API (client-server website)
3. Authentication with social media on mobile with REST API

Authentication with social media on same website (monolith website)

This is the basic flow on Socialite, we just redirect from our website to social media’s authentication page. After we authenticated on there, they will redirect back to our website, its called callback. To using this flow, you can implement this code.

Socialite with monilithic website

Authentication with social media on website with REST API (client-server website)

Similar with the flow before, the difference just we are as API provider that provide redirect to social media authentication page and received auth result. After that we check that credential on our system. To using this flow, you can implement this code.

Socialite for REST website, just add ‘stateless()’

Authentication with social media on mobile with REST API

This is the lastest flow that i knew and this is the simplest one!. Some mobile apps have they own library to authentication with social media (i.e React Native Google Signin), but the problem is how to integrate social media auth with our system. And Socialite was provide for this problem. To using this flow, you can implement this code.

Socialite for received token from mobile apps

Why we do not using 2nd flow to tackle this problem? because the 2nd flow we redirect to social media auth as website url, not open the social media apps. So the problem is after we authenticated from social media, we can not back to apps again because our position is on website (i don’t know we can use deeplink or not, not trying yet). So this flow will make it easier.

So thats all i just want to share, hope it will help you to build your great product as easy as can!

--

--