![]() ![]() You can then use whatever authentication you like to create a token etc and send it back to the user. In this method we can take the provider user that socialite gives us and we can build our real user and save the information down to our database. Which is basically just the endpoint it hits after you successfully authorize the app. However the basic idea is this: When you configure your facebook integration, or integration with any other platform. ![]() This is a very basic example and I have included some comments in my code sample to explain a few things. * for example you might do something like this if you were using JWT You can use whatever you are using for authentication here. but you could set other things like avatar or gender maybe we can set all the values on our user model if it is new. Check if a user exists with the email and if so, log them in. ![]() for example we might do something like. we have successfully authenticated via facebook at this point and can use the provider user to log us in. $providerUser = Socialite::driver('facebook')->stateless()->user() this user we get back is not our user model, but a special user object that has all the information we need * Obtain the user information from Facebook. just don't forget to include the "stateless()" function. However I like to have my frontend client apps call this backend endpoint to start the authorization process. ![]() I've seen many implementations where the "redirect to provider" functionality is provided the front end client application. I think in many scenarios this method is optional. Return Socialite::driver('facebook')->stateless()->redirect() * Redirect the user to the Facebook authentication page. If there is some interest I can add a guide for this as well. The code samples below show the social authentication portion, but you will still need to implement JWT, Oauth (passport) or some other authentication method. Note: Please keep in mind that you will still need to implement an authenticaiton system to send to send a token to a client or something after you successfully authenticate using Socialite. If you want to support multiple providers this can be easily done by passing in the provider name to your endpoint, but I'll just be hardcoding 'facebook' in my examples. For my examples I will be using Lumen and I will setup a generic endpoint that does social authentication using facebook. Socialite makes social authentication crazy easy! I will post a few code samples below to show you what it looks like in action. But maybe you still want to handle the Callback on your API side. For example maybe you are using Angular and you use a popular social authentication plugin like Satellizer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |