![]() We have completed the Laravel Login with Google, Facebook and Twitter. We have successfully configured Facebook authentication to our application. The last step is to add a Twitter Button to our login page and point to the relevant route(In this case the twitter-redirect route). ![]() $user = Socialite::driver('twitter')->user() * Obtain the user information from Twitter. The callback logic is handled as follows: /** Return Socialite::driver('twitter')->redirect() * Redirect the user to the Twitter authentication page. The first method will show the Twitter authentication page while the second method will be responsible for handling the response once a user authenticates using Twitter as the provider. We will then need to update the routes/web.php file to factor in the Twitter redirect and callback routes. 'redirect' => env('TWITTER_REDIRECT_URL')Īfter configurations, we are going to update the create a user migration file to accommodate Twitter as an authentication provider. 'client_secret' => env('TWITTER_CLIENT_SECRET'), The configurations are as shown: 'twitter' => [ We will add the credentials to the config/services.php file. We need to add the configurations to our Laravel application. This will provide us with the Twitter Client Id and App secret which we can use in our Laravel application. To do so, we need to create a Twitter application in the Twitter Developer Portal. We can also log in with Twitter in Laravel using Socialite. The last step is to add a Facebook Button to our login page and point to the relevant route(In this case the facebook-redirect route). $user = Socialite::driver('facebook')->user() * Obtain the user information from Facebook. Return Socialite::driver('facebook')->redirect() * Redirect the user to the Facebook authentication page. The first method will show the Facebook authentication page while the second method will be responsible for handling the response once a user authenticates using Facebook as the provider. With that, we have configured google authentication to our application. The last step is to add a Google Button to our frontend login page and point to the relevant route(In this case the google-redirect route). $newUser->avatar_original = $user->avatar_original $existing = User::where('email', $user->email)->first() ![]() $user = Socialite::driver('google')->user() * Obtain the user information from Google. To handle the callback logic, we can add the following code to the LoginController class: /** Return Socialite::driver('google')->redirect() * Redirect the user to the Google authentication page. To handle the redirect we can add the following logic to the LoginController Class: /** In this part, we are going to add Google authentication to our Laravel application. Once we install the socialite package, we can use it to add google authentication to our application. composer require laravel/socialite Laravel Socialite with Google To get started with laravel socialite authentication, use Composer package manager to add the dependency to your application. ![]() How to use Laravel Socialite Installation ![]() Some other Laravel socialite providers include Appleand Instagram just to name a few. The community by the name of Socialite Providers have factored in most of the other Laravel socialite Oauth providers that can be beneficial to have on your application. Developers have created other community-driven providers. Socialite currently supports authentication with Facebook, Twitter, Github, Google, LinkedIn, Bitbucket and Gitlab. With this package, a developer is able to add the social authentication aspect to their application with convenience allowing them to be productive in the process. Laravel Socialite is a package developed to ease the implementation of social authentication by removing the complexities involved. In this article, I am going to show you how to add social login implementation to your application. This has become a norm in most applications. The figure above shows an example of a login page containing both form fields for login and social login buttons for both Facebook and Twitter. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |