0% found this document useful (0 votes)
40 views

LAB-Logging in With Google Oauth: Step 1 - User Registration

The document discusses logging in to an application using Google OAuth. It describes registering as a user, adding Google OAuth dependencies, configuring client ID and secret, and handling authentication success to extract user details and save to a database if not existing. On login, the user is redirected to Google for authentication and on success their details are saved.

Uploaded by

Manmeet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

LAB-Logging in With Google Oauth: Step 1 - User Registration

The document discusses logging in to an application using Google OAuth. It describes registering as a user, adding Google OAuth dependencies, configuring client ID and secret, and handling authentication success to extract user details and save to a database if not existing. On login, the user is redirected to Google for authentication and on success their details are saved.

Uploaded by

Manmeet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

LAB- Logging in with Google Oauth

Step 1 – User Registration

In this step you will be working on 03-security-google-oauth2-start project.

Open pom.xml and observe that we have added

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>

Go to https://console.developers.google.com/

Click on Credentials link in the left menu


Click on Create credentials ,select “Oauth Client Id”

Select Application type as “Web Application”

Give Some Name , and redirect uri as https://localhost:8443/myapp/login/oauth2/code/google and


create.

Note down the client-id and client-secret shown

Now configure following in application.yml

spring:
security:
oauth2:
client:
registration:
google:
client-id: <<client-id>>
client-secret: <<client-secret>>

Open Oauth2AuthenticationSuccessHandler.java given to you in com.way2learnonline package and observe


that it is extracting user details from OAuth2AuthenticationToken
And saving MyAppUser into database if user is not existing.
Open WebSecurityConfiguration.java and complete TODO-1

Open login.html under templates folder and observe how we have added link for Google
Login

That’s all !!
Now give a request to http://localhost:8080/hello so that you will be redirected to
login page.

In the login page choose to login using google.

You should be successfully logged in.

Open http://localhost:8080/h2-console and observe that the user details are added to
Users table.

You might also like