This website uses cookies to ensure you get the best experience on our website.

Skip to content
LOGO
  • Company

    About IGNEK

    Learn about our story and our mission.

    Careers

    We're hiring!

    We always looking for talented peoples. Join our team!

    Blogs

    The latest industry news, updates and info.

    Case Studies

    Take a closer look at the projects we've delivered

    Webinar

    Watch our latest organized webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Custom Enterprise Portal Development for flawless Solutions

    Dedicated Development Team

    Expand Teams, Optimize Development with Our Expertise

    Back-end Development

    Empowering your digital presence with robust backend development expertise

    Front-end Development

    Crafting engaging user experiences through expert frontend development

    Digital Transformation

    Embrace digital transformation by modernizing process

    SaaS Development

    Transform your business with SaaS Innovative Solutions

    Technologies

    Liferay Services

    Development & Customization

    Theme

    Upgradation

    Migration

    Proof of Concept

    Performance Tunning

    Architecture

    Support & Maintenance

    E-commerce

    Expert Advice

    React Services

    Enterprise Development

    Custom Application

    Single Page Application

    Architecture

    API Integration

    Migration

    Consulting

    Maintenance & Support

    Spring Boot Services

    Web Service

    MVC Web Development

    API Integration

    Security

    Migration

    Microservices

    Support & Maintenance

    AEM Services

    Consulting Service

    Site Development

    Migration & Upgradation

    Integration

    Maintenance & Support

    Custom Solutions

    Content Management

    Team Augementation

  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Transforming industries through cutting edge SaaS solutions.

    Customer Portal : Boost Business Productivity

    Streamline operations and enhance productivity with our Customer Portal solution.

    Liferay Based Intranet Portal

    Internal portal for company communication, collaboration and resources

    Integration

    Matomo Integration with Liferay

    Integrate Matomo to enable user interactions seamlessly.

    Microsoft Teams integration with Liferay

    Integrate to enable seamless collaboration, messaging within your portal.

    Jira Integration With Liferay

    Optimizes business operations by integrating with Jira.

  • Hire Us

    Liferay

    Get expert Liferay developers for seamless portal solutions.

    React JS

    Get expert ReactJS developers for dynamic web solutions.

    Web Developer

    Get custom web solutions from IGNEK's expert developers.

    Spring Boot

    Get top-notch Spring Boot developers for your project success!

    Healthcare

    Get top Healthcare Developers for cutting-edge medical software.

    MERN Stack

    Get expert MERN developers from IGNEK for custom, innovative project solutions.

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • info@ignek.com
    • Ahmedabad, Gujarat, India – 382470
SCHEDULE CALL
  • COMPANY
    • About
    • Case Studies
    • Blogs
    • Career
    • Webinar
  • SERVICES
    • Enterprise Portal Development
    • Dedicated Development Team
    • Back-end Development
    • Front-end Development
    • Digital Transformation
    • SaaS Development
  • SOLUTION
    • Customer Portal:  Boost Business Productivity
    • SaaS : Software as a Service
    • Liferay Based Employee Intranet Portal
  • TECHNOLOGY
    • Liferay Services
      • Liferay Development and Customization
      • Liferay Theme Development Service
      • Liferay DXP 7.4 Upgrade
      • Liferay Migration
      • Liferay Proof Of Concept
      • Liferay Performance Tuning
      • Liferay Architecture Design Service
      • Liferay Support And Maintenance Service
      • Liferay Ecommerce Development
      • Liferay Expert Advice
    • ReactJS Services
      • ReactJS Enterprise Application Development
      • ReactJS Custom Application Development
      • ReactJS Single Page Application Development (SPA)
      • ReactJS Applications Architecture
      • ReactJS API Integration
      • ReactJS Migration
      • ReactJS Consulting
      • ReactJS Maintenance and Support
    • Spring Boot Services
      • Spring Boot Web Development Service
      • Spring MVC Web Development
      • Spring Boot API Integration Service
      • Spring Boot Security
      • Spring Boot Migration Service
      • Spring Boot Microservices
      • Spring Boot Support & Maintenance Service
    • AEM Development Services
      • AEM Consulting Services
      • AEM Site Development
      • AEM Migration & Upgradation
      • AEM Integration Services
      • AEM Maintenance & Support
      • AEM Content Management
      • Custom AEM Solutions
      • AEM Team Augmentation
  • INTEGRATION
  • HIRE US
    • Hire Liferay Developer
    • Hire ReactJS Developer
    • Hire Spring Boot Developer
    • Hire Healthcare Developer
    • Hire Web Developer
    • Hire MERN Stack Developer
  • CONTACT US
  • Company

    About IGNEK

    Careers

    We're hiring!

    Blogs

    Case Studies

    Webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Dedicated Development Team

    Back-end Development

    Front-end Development

    Digital Transformation

    SaaS Development

    Technologies

    Liferay Liferay Services
    • Development & Customization
    • Theme
    • Upgradation
    • Migration
    • Proof of Concept
    • Performance Tuning
    • Architecture
    • Support & Maintenance
    • E-commerce
    • Expert Advice
    React React Services
    • Enterprise Development
    • Custom Application
    • Single Page Application
    • Architecture
    • API Integration
    • Migration
    • Consulting
    • Maintenance & Support
    Spring Boot Spring Boot Services
    • Web Service
    • MVC Web Development
    • API Integration
    • Security
    • Migration
    • Microservices
    • Support & Maintenance
    AEM AEM Services
    • Consulting Service
    • Site Development
    • Migration & Upgradation
    • Integration
    • Maintenance & Support
    • Custom Solutions
    • Content Management
    • Team Augmentation
  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Customer Portal : Boost Business Productivity

    Liferay Based Intranet Portal

    Integration

    Matomo Integration with Liferay

    Microsoft Teams integration with Liferay

    Jira Integration With Liferay

  • Hire Us

    Liferay

    React JS

    Web Developer

    Spring Boot

    Healthcare

    MERN Stack

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • IGNEK
    • Ahmedabad, Gujarat, India – 382470
  • SCHEDULE CALL

OAuth 2.0 Authentication In Spring Boot

  • Spring Boot
  • August 12, 2024

Share On :

Introduction

OAuth 2.0 is a popular method for allowing applications to access user data without needing their passwords. It’s especially useful when you want to let one application access another application’s data.

OAuth 2.0 is an authorization framework that allows applications to obtain limited access to user accounts on an HTTP service, such as Facebook, GitHub, or Google, without exposing user credentials. 

OAuth 2.0 is a security protocol that allows one application (the client) to access resources (like user data) hosted on another server (the resource server) on behalf of the user (the resource owner). This process is managed by an authorization server.

OAuth2 is a popular authorization framework that allows third-party applications to access a user’s data without exposing their credentials. In this blog post, we’ll walk through the process of implementing OAuth2 login in a Spring Boot application using GitHub as the authentication provider.

Prerequisites
  • JDK 11 or later
  • Maven or Gradle
  • Any authorization server account
What is actually OAuth

Take an example of a teamviewer.

If you are a new user you need to sign up. You can sign up using google or microsoft or apple account. When doing so you are authorizing Google or microsoft or apple to allow teamviewer to access your profile info with teamviewer. This authorization is done using OAuth.

 

Key Components of OAuth 2.0
  • Resource Owner: The user who owns the data.
  • Client: The application requesting access to the user’s data.
  • Resource Server: The server that has the protected user data.
  • Authorization Server: The server that issues tokens to the client after the user grants permission.
How OAuth 2.0 Works
Teamviwer_sign_in_page
  • The client requests authorization from the user.
  • If the user approves, the client gets an authorization grant.
  • The client exchanges the authorization grant for an access token from the authorization server.
  • The client uses the access token to request the user’s data from the resource server.
  • The resource owner will then use OAuth to authorize the resource server to share data with the client application.
  • The client application must first register with the authorization server associated with the resource server. This is usually a one-time task. Once registered, the registration remains valid, unless the client application registration is revoked. At registration the client application is assigned a client ID and a client secret (password) by the authorization server. The client ID and secret is unique to the client application on that authorization server.
  • For example if we click on Continue with Google, we get the following screen. Here we can see teamviewer client id.



oAuth2_workflow

In the above example of teamviewer, we have 4 actors-

  • Resource Owner – This is the user who wants to sign up using teamviewer.
  • Client Application – This will be teamviewer
  • Resource Server – This will be Gmail or microsoft,apple.
  • Authorization Server – The resource server hosts the protected user accounts, and the authorization server verifies the identity of the user then issues access tokens to the application.

In this blog post, we’ll walk through the process of implementing OAuth2 login in a Spring Boot application using GitHub as the authentication provider.

Step 1 : Create a GitHub OAuth Application

  • Go to GitHub and log in.
  • Navigate to Settings > Developer settings > OAuth Apps.
  • Click New OAuth App.
  • Fill in the application details. The Authorization callback URL should be http://localhost:8080/login/oauth2/code/github.
  • Once created, take note of the Client ID and Client Secret.

Step 2 : Set Up Your Spring Boot Application 

Create a Spring Boot Project

You can create a new Spring Boot project using Spring Initializr (https://start.spring.io/). Add the following dependencies:

  • Spring Web
  • Spring Security
  • Spring Boot OAuth2 Client

Configure Application Properties

Add the following configuration to application.yml:

teamviwer_gmail_redirect_page

Replace YOUR_CLIENT_ID andYOUR_CLIENT_SECRET with the values from your GitHub OAuth application.

Create the Security Configuration

Create a SecurityConfig class to configure Spring Security:

Here, The filterChain method configures Spring Security to ensure that all incoming HTTP requests are authenticated and sets up OAuth2 login.

				
					package com.ignek.oauth_int.config;

import static org.springframework.security.config.Customizer.withDefaults;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
public class SecurityConfig {
  @Bean
  public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http.authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
        .oauth2Login(withDefaults());

    return http.build();
  }
}

				
			

Create a REST Controller

Create an OAuthController to handle requests:

				
					package com.ignek.oauth_int.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/v1/demo")
public class OAuthController {

  @GetMapping
  public ResponseEntity<String> test() {
    return ResponseEntity.ok("Hello from secure endpoint");
  }
}


				
			

 The Main Application Class

				
					package com.ignek.oauth_int;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class OauthIntApplication {
  public static void main(String[] args) {
    SpringApplication.run(OauthIntApplication.class, args);
  }
}

				
			

Run Your Application

Run your Spring Boot application. Navigate to http://localhost:8080/api/v1/demo in your browser. You should be redirected to GitHub to authorize the application. After authorizing, you’ll be redirected back to your application and see the message “Hello from secure endpoint”.

Output
demo_application_output
Conclusion

In conclusion, we know how to implement OAuth2 login in a Spring Boot application using GitHub as the authentication provider. This setup allows users to log in to your application securely without needing to create a separate account, leveraging their existing GitHub credentials. This approach can be extended to other OAuth2 providers like Google, Facebook, and more.

 

 

Explore Our Services

Discover how we can help your business thrive, whether you’re running a small startup, an SME, or a large enterprise. We’re here to understand your unique needs and goals, offering the expertise and resources to support your journey to success.

Stay informed about our Spring Boot services and updates by subscribing to our newsletter—just fill in the details below to subscribe.

Loading
Loading...

Related Blogs

October 17, 2023
Enhance program organization and structure through Spring Boot Custom Annotations.
Custom Annotations in Spring Boot
March 28, 2024
Spring Boot With Docker
Dockerize Spring Boot Application
August 12, 2024
Spring Security 6_ JWT Authentication & Authorization_
Spring Security 6 : JWT Authentication & Authorization
Loading...

Featured Projects Portfolios

October 6, 2023
Dynamic E-commerce Platform_for Sales, Rentals and Inventory Management
Dynamic E-commerce Platform for sales, Rentals and Inventory Management

Digital Solutions for Your Business with IGNEK

4.9

5.0

5.0

5.0

LOGO

Making the world a better place through constructing elegant hierarchies

COMPANY

  • About
  • Career
  • Case Study
  • Blogs

SERVICES

  • Enterprise Portal Development
  • Dedicated Development Team
  • Back-end Development
  • Front-end Development
  • Digital Transformation
  • SaaS Development

HIRE US

  • Liferay
  • Spring Boot
  • ReactJS
  • Healthcare
  • MERN Stack
  • AEM

CONTACT

  • info@ignek.com
  • info@ignek.com
SALES
  • sales@ignek.com
  • (+91) 635 157 6580
CAREER
  • hr@ignek.com
  • (+91) 932 849 5160
  • E 910-912, Ganesh Glory 11, Jagatpur Road, SG Highway, Ahmedabad, Gujarat - 382470

© 2018-2025 IGNEK, Inc. All rights reserved

Linkedin Facebook X-twitter Instagram