laravelflutterlaravel-socialite

Log-in users in flutter through social accounts with laravel-socialite backend


I am working on a flutter application, and I want to implement social login (Google and Facebook).

My API is implemented with Laravel and uses Laravel-socialite to authenticate users, there is the backend, web frontend (using VueJs) and now I am working on the mobile application using flutter.

The web application is working good (using the vue-social-auth package).

What I have done till now:

  1. Used flutter_google_sign_in to handle authentication on the flutter app.
  2. Did configure the package and I can successfully get user info through that package.

Problem I am facing:

What I don't seem to get working is to send the user that just logged in to the backend in order to provide an in-app user experience.

This is what the vue-social-auth package provides and what I send to the backend, which is working fine:

{code: "4/0AY0e-g442SMxdtLb_MVdQ63u1ydp48bbCRQco5Azoyf3y1rvYybDabyZGOvwAs7ZFJDQHA", scope: "email+profile+openid+https://www.googleapis.com/au…le+https://www.googleapis.com/auth/userinfo.email", authuser: "0", prompt: "consent"}

And this is what flutter_google_sign_in gives (aside of the user profile data:

idToken: "",
accessToken: "",
serverAuthCode: "", 

serverAuthCode is always null.

How can I make it so that, using the same API logic, log-in users on flutter through social accounts?

Thank you.


Solution

  • I have solved it, after some digging I found out Laravel-Socialite has the functionality to log in users using their token built-in:

    Quoting Socialite documentation:

    If you already have a valid access token for a user, you can retrieve their details using Socialite's userFromToken method.