A Spring Boot backend application for the Sport Clubs UI application with Google OAuth2 authentication.
- User authentication via Google OAuth2
- User management with JPA and PostgreSQL
- RESTful API endpoints for user data
- CORS support for frontend integration
- Session management with JDBC
- JDK 21
- Maven
- PostgreSQL database
- Google Developer Console account
- Make sure PostgreSQL is running
- Create a database named
sportclubs
- Go to the Google Developer Console
- Create a new project
- Enable the Google+ API
- Create OAuth2 credentials (Web application type)
- Add authorized redirect URIs:
http://localhost:8080/login/oauth2/code/google- Your production URL if applicable
- Note your Client ID and Client Secret
- Copy the
.env.examplefile to.env - Update the
.envfile with your Google OAuth2 credentials:GOOGLE_CLIENT_ID=your_google_client_id GOOGLE_CLIENT_SECRET=your_google_client_secret - Configure other settings as needed (database credentials, etc.)
mvn spring-boot:rundocker-compose -f docker-compose-dev.yml upGET /api/public/health- Check application healthGET /api/public/oauth2/login-options- Get OAuth2 login options
GET /oauth2/authorization/google- Initiate Google OAuth2 loginGET /api/auth/login/success- OAuth2 login success handlerGET /api/auth/login/failure- OAuth2 login failure handlerGET /api/auth/logout- LogoutGET /api/auth/user- Get current authenticated user
GET /api/users/me- Get current userGET /api/users/{id}- Get user by ID
Your frontend application should:
- Redirect the user to
/oauth2/authorization/googlefor login - Set up CORS in your frontend to include credentials
- Use session cookies for authentication