Login to the App with Google Account

Tram Ho

Hello friends! Today I would like to share with you a small application that in any admin page is indispensable, that is the longin function to authenticate user accounts before they access the system. But today we will not login in the usual way, create a login form so that the user can enter the user and password as usual, but I want to divide the login into an application via google account. your. Now to create more convenience for users, as well as help users not to create too many accounts and to remember each account to access and each system. Website applications have created many utilities for creating accounts such as you can login with your Google account, facebook or github..vv. This not only helps users do not need to waste more time creating a new account and then have to remember it every time you want to log into the system. And today I will work with you to make a small login application through your own google account, we will create this application based on the framework of the Laravel framework offline..Let’s go.

Steps To Perform

  1. Install laravel 6 application
  2. Database setup
  3. Install the support package
  4. How to get an account from google
  5. Create Route
  6. Create Controller & Methods
  7. Create view
  8. Run the development server
  9. Conclusion

1. Install laravel application 6.

To start of course we need to download the laravel to your local, here I will download the latest version. You can type or copy your command below to quickly.

  • For those new to laravel, if you want to run the command on the terminal (ubuntu), CMD (window), you should install the composer first.

2. Set up the database.

Next step, after downloading laravel to your device, open the .env file and set some information.

  • Note this step needs to set up the correct information with your database on phpmyadmin.

3. Install the package.

In this step we will install a package already supported by laravel so we can connect to google.

After successfully installing the social package, we need to configure aliese and provider in config / app.php.

4. How to get an account from google.

First of all, we need to have CLIENT ID and CLIENT SECRET to add social google login button in laravel based project, go to https://console.developers.google.com/ and create a new application. If you are not familiar with creating then you can search google, there are many instructions, this article I am not convenient to just step here 😃 ). After successfully creating an application in Google and receiving login information from the Google control panel, go to config / service.php and add the configuration below:

Next you move to the App / User.php file and change as the code below.

Continue on you go to app / database / create_users_table.php and change the code as below.

After that you need to create an auth for login.

And run the command to create the data base is executed.

If in the process of running the error, you go to the file app / providers / AppServiceProvider.php and add the following code line.

5. Create route.

You navigate to routes / web.php and create routes as shown below.

6. Create COntroller.

Next we create the Controller.

After successfully creating, access app / controls / SocialControll.php and put the following code:

  1. Socialite :: driver (‘$ provider’) -> redirect () is called, this processing task redirects the user to the Google authentication page.
  2. After successful authentication, it will redirect to Authorization callback URL and take user data.
  3. Save user information and login. Now we move to Resources / Views / Auth, and create a balde register.blade.php, we will create a login button using google.

Navigate to Resources / Views / Auth / login.blade.php and add the code below.

8. Run the server

You run the command line below to run serve.

If the port you configured is not the default port 80, then we will run up the command as shown below.

9. Conclusion.

That’s it, I have just shared with you a small application for logging in with your google account in laravel, wish you success. In the following post, I will share with you the login with your github account.

Share the news now

Source : Viblo