How to implement OAuth Login (Single Sign-on) using Google & Java(Spring Boot) — Part 2

rohan2596

Rohan Ravindra Kadam

Posted on November 20, 2021

How to implement OAuth Login (Single Sign-on) using Google & Java(Spring Boot) — Part 2

OAuth2 Google

Hello All, Its Rohan Kadam

In previous part 1, we looked into how to create projects and keys and credentials. Let us look into code for implementing OAuth Login in Spring boot

Google OAuth using Java and Spring Boot -Part 2

Follow the below article for Google Configuration.
How to implement OAuth2 Login Using Google — Part 1

Step 1:- Create a Spring Boot Project using Spring initializer.

Spring Initializr

Step 2:- Add the following dependencies in your project pom.xml

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-oauth2-client</artifactId>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Step 3:- Create a Configuration File for implementing OAuth2.

Step 4:- Create Application Yml which will consist of Google Configuration.

Step 5:- Create a Rest Controller which consists of two endpoints.


Note:-
  1. Principal Object contains username, email and profile image depending on scope.

  2. If an error occurs regarding an incorrect redirect Url add the following URL **https://localhost:8080/oauth2/callback/google**

Thank You

💖 💪 🙅 🚩
rohan2596
Rohan Ravindra Kadam

Posted on November 20, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Mystery of Closures in JavaScript!
javascript Mystery of Closures in JavaScript!

November 23, 2024

JS Variables, Operators, Data Types
javascript JS Variables, Operators, Data Types

July 10, 2024

JS Introduction
javascript JS Introduction

July 10, 2024

JS Function, Object, String
javascript JS Function, Object, String

July 11, 2024

My first node API
javascript My first node API

March 23, 2024