Skip to content

About

Spring Boot OAuth2 Multi-Provider Authentication with Professional UI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Spring OAuth2 Multi-Provider Authentication System

A comprehensive Spring Boot 3.x application demonstrating modern authentication patterns with OAuth2 integration across multiple providers. This project showcases enterprise-grade security implementation with both traditional form login and OAuth2 social login capabilities.

Spring Boot Java

โœจ Features

๐Ÿ” Authentication Methods

  • โœ… Form-based Authentication (Username/Password)
  • โœ… Google OAuth2 Integration
  • โœ… GitHub OAuth2 Integration
  • โœ… LinkedIn OAuth2 Integration
  • โœ… Microsoft OAuth2 Integration

๐ŸŽจ User Experience

  • ๐ŸŽฏ Professional UI with Modern Design
  • ๐ŸŽจ Responsive Layout with Gradient Backgrounds
  • ๐ŸŽญ FontAwesome Icons for Provider Branding
  • ๐Ÿ“ฑ Mobile-Friendly Interface
  • โšก Smooth Animations and Transitions

๐Ÿ”’ Security Features

  • ๐Ÿ›ก๏ธ CSRF Protection on all forms
  • ๐Ÿ” Session Management with proper invalidation
  • ๐Ÿšช Secure Logout with POST method
  • ๐Ÿ‘ค Role-based Access Control setup
  • ๐Ÿ”‘ Spring Security 6.x latest version

๐Ÿ“Š User Information Display

  • ๐Ÿ‘ค User Profile Information
  • ๐Ÿ” Authentication Method Detection
  • ๐Ÿ“‹ Detailed Attributes Display
  • ๐ŸŽฏ Provider-specific Data Handling

๐Ÿ—๏ธ Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Frontend      โ”‚    โ”‚   Spring MVC     โ”‚    โ”‚   Database      โ”‚
โ”‚   (Thymeleaf)   โ”‚โ—„โ”€โ”€โ–บโ”‚   Controllers    โ”‚โ—„โ”€โ”€โ–บโ”‚   (In-Memory)   โ”‚
โ”‚                 โ”‚    โ”‚                  โ”‚    โ”‚                 โ”‚
โ”‚ โ€ข Login Forms   โ”‚    โ”‚ โ€ข AuthController โ”‚    โ”‚ โ€ข User Store    โ”‚
โ”‚ โ€ข User Dashboardโ”‚    โ”‚ โ€ข SecurityConfig โ”‚    โ”‚ โ€ข Sessions      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                       โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  Spring Security   โ”‚
                    โ”‚                    โ”‚
                    โ”‚ โ€ข OAuth2 Clients   โ”‚
                    โ”‚ โ€ข Form Login       โ”‚
                    โ”‚ โ€ข CSRF Protection  โ”‚
                    โ”‚ โ€ข Session Mgmt     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“š Learning Outcomes

This project demonstrates advanced concepts in:

๐Ÿ” Security & Authentication

  • OAuth2 Protocol implementation
  • Spring Security configuration patterns
  • CSRF Protection mechanisms
  • Session Management best practices

๐Ÿš€ Spring Boot Ecosystem

  • Spring Boot 3.x with Jakarta EE
  • Spring Security 6.x integration
  • Thymeleaf templating engine
  • Maven build management
  • Dependency Injection patterns

๐ŸŽจ Frontend Integration

  • Responsive HTML/CSS design
  • FontAwesome icon integration
  • Thymeleaf expressions and conditionals
  • Form handling with validation

๐Ÿ› ๏ธ Development Skills

  • Multi-provider OAuth2 setup
  • Error handling and debugging
  • Configuration management
  • RESTful API development

๐Ÿš€ Quick Start

Prerequisites

  • โ˜• Java 17 or higher
  • ๐Ÿ—๏ธ Maven 3.6+
  • ๐ŸŒ Internet connection for OAuth2 providers

Demo Mode (No Setup Required)

# Clone the repository
git clone https://github.com/your-username/spring-oauth2-demo.git
cd spring-oauth2-demo

# Run the application
./mvnw spring-boot:run

Demo Credentials:

  • Username: user
  • Password: password

Production Setup with OAuth2

1. Google OAuth2 Setup

  1. Visit Google Cloud Console
  2. Create/select a project
  3. Enable Google Identity API
  4. Navigate to APIs & Services โ†’ Credentials
  5. Create OAuth 2.0 Client ID
  6. Add redirect URI: http://localhost:8080/login/oauth2/code/google

2. GitHub OAuth2 Setup

  1. Go to GitHub Developer Settings
  2. Click "New OAuth App"
  3. Set Authorization callback URL: http://localhost:8080/login/oauth2/code/github
  4. Note down Client ID and Client Secret

3. LinkedIn OAuth2 Setup

  1. Visit LinkedIn Developers
  2. Create a new application
  3. Configure OAuth 2.0 settings
  4. Add redirect URL: http://localhost:8080/login/oauth2/code/linkedin

4. Microsoft OAuth2 Setup

  1. Go to Azure Portal
  2. Navigate to Azure Active Directory โ†’ App registrations
  3. Create new registration
  4. Add redirect URI: http://localhost:8080/login/oauth2/code/microsoft

Configuration

Update src/main/resources/application.properties:

# Default User Credentials (Form Login)
spring.security.user.name=user
spring.security.user.password=password
spring.security.user.roles=USER

# OAuth2 Client Configurations
spring.security.oauth2.client.registration.google.client-id=your-google-client-id
spring.security.oauth2.client.registration.google.client-secret=your-google-client-secret

spring.security.oauth2.client.registration.github.client-id=your-github-client-id
spring.security.oauth2.client.registration.github.client-secret=your-github-client-secret

# Add similar configurations for LinkedIn and Microsoft

๐ŸŽฎ Usage Guide

Starting the Application

./mvnw spring-boot:run

The application will start on http://localhost:8080

Authentication Flow

  1. Access Application: Navigate to http://localhost:8080
  2. Choose Login Method:
    • Form Login: Use demo credentials (user/password)
    • OAuth2 Login: Click any provider button
  3. Authentication: Complete OAuth2 flow or form submission
  4. Dashboard: View user information and authentication details

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

๐Ÿ“ Project Structure

spring-oauth2-demo/
โ”œโ”€โ”€ src/main/java/com/shubh/SpringOAuth2/
โ”‚   โ”œโ”€โ”€ SpringOAuth2Application.java      # Main application class
โ”‚   โ”œโ”€โ”€ AuthController.java               # Authentication controller
โ”‚   โ””โ”€โ”€ SecurityConfig.java               # Security configuration
โ”œโ”€โ”€ src/main/resources/
โ”‚   โ”œโ”€โ”€ application.properties            # Application configuration
โ”‚   โ””โ”€โ”€ templates/
โ”‚       โ”œโ”€โ”€ login.html                    # Login page template
โ”‚       โ””โ”€โ”€ home.html                     # Dashboard template
โ”œโ”€โ”€ pom.xml                               # Maven configuration
โ””โ”€โ”€ README.md                            # Project documentation

๐Ÿ”Œ API Endpoints

Endpoint Method Description Authentication
/ GET Redirects to login Public
/login GET Login page Public
/perform_login POST Form login processing Public
/home GET User dashboard Private
/perform_logout POST Logout processing Private
/oauth2/authorization/* GET OAuth2 authorization Public

๐Ÿ› ๏ธ Technologies & Dependencies

Technology Version Purpose
Spring Boot 3.5.5 Application framework
Spring Security 6.5.3 Authentication & authorization
Spring OAuth2 Client 6.5.3 OAuth2 integration
Thymeleaf 3.1.3 Template engine
FontAwesome 6.0.0 UI icons
Java 17 Programming language
Maven 3.9+ Build tool

๐Ÿ”ง Configuration Details

Security Configuration Features

  • โœ… Multi-provider OAuth2 support
  • โœ… Form-based authentication fallback
  • โœ… CSRF protection on all forms
  • โœ… Session management with invalidation
  • โœ… Role-based access control
  • โœ… Custom login/logout URLs

OAuth2 Provider Support

Provider Status Configuration Required
Google โœ… Ready Client ID/Secret needed
GitHub โœ… Ready Client ID/Secret needed
LinkedIn โœ… Ready Client ID/Secret needed
Microsoft โœ… Ready Client ID/Secret needed

๐Ÿ› Troubleshooting

Common Issues

1. OAuth2 Connection Failed

Error: Invalid client credentials

Solution: Ensure OAuth2 client credentials are correctly configured in application.properties

2. CSRF Token Errors

Error: Invalid CSRF token

Solution: CSRF tokens are automatically handled. Try refreshing the page.

3. Template Errors

Error: Template processing failed

Solution: Ensure all Thymeleaf expressions are properly formatted.

4. Port Already in Use

Error: Port 8080 is already in use

Solution: Change port in application.properties:

server.port=8081

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is currently unlicensed. You can add a license by creating a LICENSE file in the root directory with your preferred license terms.

๐Ÿ™ Acknowledgments

  • Spring Boot team for excellent documentation
  • OAuth2 providers for their APIs
  • Open source community for inspiration

๐Ÿ“ž Support

If you have any questions or issues:


๐Ÿš€ GitHub Upload Instructions

Step 1: Initialize Git Repository

# Initialize git in your project directory
git init
git add .
git commit -m "feat: Add comprehensive OAuth2 multi-provider authentication system

- Implement Spring Security 6.x with OAuth2 client
- Add support for Google, GitHub, LinkedIn, Microsoft OAuth2
- Create professional UI with Thymeleaf templates
- Add CSRF protection and secure session management
- Include form-based authentication as fallback
- Add comprehensive documentation and setup guide"

Step 2: Create GitHub Repository

  1. Go to GitHub.com
  2. Click "New repository"
  3. Name it: spring-oauth2-demo or multi-provider-auth-spring
  4. Add description: "Spring Boot OAuth2 Multi-Provider Authentication with Professional UI"
  5. Choose Public repository
  6. DO NOT initialize with README (we already have one)

Step 3: Push to GitHub

# Add your GitHub repository as remote
git remote add origin https://github.com/your-username/your-repo-name.git

# Push to GitHub
git branch -M main
git push -u origin main

Step 4: Add Repository Topics

After uploading, add these topics to your repository:

  • spring-boot
  • spring-security
  • oauth2
  • authentication
  • java
  • thymeleaf
  • maven
  • web-development

Step 5: Create Release (Optional)

# Create a git tag
git tag -a v1.0.0 -m "Initial release with OAuth2 multi-provider authentication"

# Push the tag
git push origin v1.0.0

โญ Star this repository if you found it helpful!

Happy coding! ๐Ÿš€โœจ


Built with โค๏ธ using Spring Boot 3.x and modern web technologies

About

Spring Boot OAuth2 Multi-Provider Authentication with Professional UI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages