A Spring Boot OAuth2 Authentication Demo
Implemented secure login using GitHub OAuth
for authentication and authorization.
Spring_Oauth_Demo is a sample project that demonstrates how to implement OAuth 2.0 authentication in a Spring Boot application using GitHub as an OAuth Provider. It showcases how to integrate third-party OAuth providers for secure login, protecting routes, and retrieving authenticated user details.
✔️ OAuth 2.0 Login with GitHub – Authenticate users via their GitHub accounts.
✔️ Spring Security Integration – Secure endpoints and restrict unauthorized access.
✔️ User Information Retrieval – Fetch user profile data from GitHub after login.
✔️ Session Handling – Maintain secure sessions for authenticated users.
✔️ Lightweight Demo – Simple project structure for learning and extending OAuth with Spring.
- Backend: Spring Boot, Spring Security, OAuth2 Client
- OAuth Provider: GitHub
- Build Tool: Maven
- Database (Optional): H2 / PostgreSQL (can be configured)
- Create a new OAuth App on GitHub Developer Settings.
- Copy the Client ID and Client Secret.
- Add them to your
application.properties
file:
application.properties
spring.security.oauth2.client.registration.github.client-id=YOUR_CLIENT_ID
spring.security.oauth2.client.registration.github.client-secret=YOUR_CLIENT_SECRET
spring.security.oauth2.client.registration.github.scope=read:user,user:email
- Clone the repository:
git clone https://github.com/your-username/Spring_Oauth_demo.git
cd Spring_Oauth_demo
- Build and run with Maven:
mvn spring-boot:run
- Open your browser and go to:
http://localhost:8080/login
- Login with your GitHub account 🎉
Spring_Oauth_demo/
│── src/main/java/com/oauthdemo/ # Java source files
│ ├── controller/ # Controllers and endpoints
│ ├── config/ # Spring Security OAuth configurations if you wants to add
│
│── src/main/resources/
│ ├── application.properties # GitHub OAuth credentials
│
│── pom.xml # Maven dependencies
🔹 Add support for Google, Facebook, LinkedIn OAuth.
🔹 Store authenticated users in a PostgreSQL database.
🔹 Extend with JWT Token-based authentication.
🔹 Deploy on Heroku/AWS for production.
🔐 Built with Spring Boot and OAuth2 for secure authentication.