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.
- โ Form-based Authentication (Username/Password)
- โ Google OAuth2 Integration
- โ GitHub OAuth2 Integration
- โ LinkedIn OAuth2 Integration
- โ Microsoft OAuth2 Integration
- ๐ฏ Professional UI with Modern Design
- ๐จ Responsive Layout with Gradient Backgrounds
- ๐ญ FontAwesome Icons for Provider Branding
- ๐ฑ Mobile-Friendly Interface
- โก Smooth Animations and Transitions
- ๐ก๏ธ 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 Profile Information
- ๐ Authentication Method Detection
- ๐ Detailed Attributes Display
- ๐ฏ Provider-specific Data Handling
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ 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 โ
โโโโโโโโโโโโโโโโโโโโโโ
This project demonstrates advanced concepts in:
- OAuth2 Protocol implementation
- Spring Security configuration patterns
- CSRF Protection mechanisms
- Session Management best practices
- Spring Boot 3.x with Jakarta EE
- Spring Security 6.x integration
- Thymeleaf templating engine
- Maven build management
- Dependency Injection patterns
- Responsive HTML/CSS design
- FontAwesome icon integration
- Thymeleaf expressions and conditionals
- Form handling with validation
- Multi-provider OAuth2 setup
- Error handling and debugging
- Configuration management
- RESTful API development
- โ Java 17 or higher
- ๐๏ธ Maven 3.6+
- ๐ Internet connection for OAuth2 providers
# Clone the repository
git clone https://github.com/your-username/spring-oauth2-demo.git
cd spring-oauth2-demo
# Run the application
./mvnw spring-boot:runDemo Credentials:
- Username:
user - Password:
password
- Visit Google Cloud Console
- Create/select a project
- Enable Google Identity API
- Navigate to APIs & Services โ Credentials
- Create OAuth 2.0 Client ID
- Add redirect URI:
http://localhost:8080/login/oauth2/code/google
- Go to GitHub Developer Settings
- Click "New OAuth App"
- Set Authorization callback URL:
http://localhost:8080/login/oauth2/code/github - Note down Client ID and Client Secret
- Visit LinkedIn Developers
- Create a new application
- Configure OAuth 2.0 settings
- Add redirect URL:
http://localhost:8080/login/oauth2/code/linkedin
- Go to Azure Portal
- Navigate to Azure Active Directory โ App registrations
- Create new registration
- Add redirect URI:
http://localhost:8080/login/oauth2/code/microsoft
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./mvnw spring-boot:runThe application will start on http://localhost:8080
- Access Application: Navigate to
http://localhost:8080 - Choose Login Method:
- Form Login: Use demo credentials (user/password)
- OAuth2 Login: Click any provider button
- Authentication: Complete OAuth2 flow or form submission
- Dashboard: View user information and authentication details
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
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
| 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 |
| 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 |
- โ 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
| Provider | Status | Configuration Required |
|---|---|---|
| โ Ready | Client ID/Secret needed | |
| GitHub | โ Ready | Client ID/Secret needed |
| โ Ready | Client ID/Secret needed | |
| Microsoft | โ Ready | Client ID/Secret needed |
Error: Invalid client credentials
Solution: Ensure OAuth2 client credentials are correctly configured in application.properties
Error: Invalid CSRF token
Solution: CSRF tokens are automatically handled. Try refreshing the page.
Error: Template processing failed
Solution: Ensure all Thymeleaf expressions are properly formatted.
Error: Port 8080 is already in use
Solution: Change port in application.properties:
server.port=8081- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is currently unlicensed. You can add a license by creating a LICENSE file in the root directory with your preferred license terms.
- Spring Boot team for excellent documentation
- OAuth2 providers for their APIs
- Open source community for inspiration
If you have any questions or issues:
- Create an issue
- Check the troubleshooting section
- Review the setup instructions
# 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"- Go to GitHub.com
- Click "New repository"
- Name it:
spring-oauth2-demoormulti-provider-auth-spring - Add description: "Spring Boot OAuth2 Multi-Provider Authentication with Professional UI"
- Choose Public repository
- DO NOT initialize with README (we already have one)
# 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 mainAfter uploading, add these topics to your repository:
spring-bootspring-securityoauth2authenticationjavathymeleafmavenweb-development
# 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