How gautamkr538/oauth2loginwithjwt works
Project type and purpose
• This is a standalone Spring Boot microservice whose sole responsibility is to handle user authentication and authorization via Google OAuth 2.0, issue JWTs, and manage refresh tokens.
• There is no separate “frontend” folder, and all code lives under src/main/java, indicating a back-end service.
File structure
• Top-level artifacts
• pom.xml / mvnw: this is a Maven-based Java project.
• src/main/java/com/oath/login: contains all source code.
• src/main/resources/application.properties + schema.sql: configuration and DB schema.
• Layered folders under com.oath.login:
• config: security and bean setup (SecurityConfig, JwtService, filters, etc.)
• controller: REST entry points (AuthController, OAuth2CallbackController)
• service: business logic (AuthService, RefreshTokenService)
• repository: DB access (UserRepository, RefreshTokenRepository)
• model: domain objects and JPA entities (User, RefreshToken)
• dto: data‐transfer objects for request/response
• exception: custom exceptions and global handler
• Testing
• src/test/java contains a basic SpringBootTest suite.
README for additional insights
• The README is a placeholder, so we rely wholly on code structure for architectural inference.
a. Main components
1. Client (mobile or web application)
2. API Gateway or client consumer that calls our AuthService endpoints
3. AuthController – exposes endpoints:
• /auth/login (email/password)
• /auth/refresh
• /oauth2/callback (Google OAuth2 redirect)
4. SecurityConfig + JwtAuthenticationFilter – intercepts requests, validates JWT
5. JwtService – creates/verifies tokens
6. AuthService & RefreshTokenService – core business logic
7. Repositories (UserRepository, RefreshTokenRepository) – JPA interface to relational DB
8. Database – stores user info and refresh tokens
9. External Google OAuth 2.0 Provider
b. Relationships & data flow
• Client → AuthController: sends credentials or OAuth redirect
• AuthController → AuthService/RefreshTokenService
• AuthService → JwtService (generate access token)
• AuthService/RefreshTokenService → Repositories (persist or load tokens)
• SecurityConfig + JwtFilter → intercept all protected calls, consult JwtService → allow/deny
• OAuth callback → OAuth2CallbackController → AuthService
• AuthService → Google OAuth provider (token exchange)
• Database ←→ Repositories
c. Architectural patterns/design principles
• Layered architecture (Controller → Service → Repository)
• Dependency injection via BeanConfig and Spring annotations
• JWT‐based stateless authentication with an optional stateful refresh token store
• Exception handling via GlobalExceptionHandler
d. Key technologies/frameworks
• Spring Boot, Spring Security, Spring Data JPA, Maven
• JWT library (built into JwtService)
• Google OAuth 2.0 API (HTTP calls or Spring OAuth clients)
• H2 or MySQL/PostgreSQL (depending on application.properties)