joselfonseca / lighthouse-graphql-passport-auth

Add GraphQL mutations to get tokens from passport for https://lighthouse-php.com/
https://lighthouse-php-auth.com/
MIT License
228 stars 56 forks source link

How to actually use with Socialite #168

Closed dylmye closed 11 months ago

dylmye commented 12 months ago

Hey, thanks for the awesome work. I would really appreciate an example usage of Socialite. The docs only provide information on the trait and the static byOAuthToken method. But what should I be doing in the oauth callback? What's the expected flow here?

Thanks in advance

joselfonseca commented 11 months ago

@dylmye The expected flow is that your Frontend, native or SPA app will use the social provider SDK for the tech used on the front to handle the social login. Like the Facebook login button. Once you have an access token from your social provider you send it to the mutation and socialite will use the token to authenticate the user in your GraphQL server. This is because in a iOS app for example, the SDK for the social provider handles everything needed to do that and we don't want to do like a web view to open a socialite page or login on the browser when the SDK can use the actual installed app to do the login. This use case was designed like this mostly because most of the use cases for the GraphQL server are mobile apps that don't use web views for login with facebook and stuff like that and we needed to get a token without username and password but with the session from a social network. Hope it makes sense and if you don't have any other question please close the issue. I honestly don't have much time right now to create a Frontend app and implement the whole thing as a demo but I can look into add more details to the docs later on.

dylmye commented 11 months ago

Great thank you. I think my confusion laid in looking at Socialite docs and confused how to use their redirect/callback methods. Appreciate you taking time to help!