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.example
file to.env
- Update the
.env
file 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:run
docker-compose -f docker-compose-dev.yml up
GET /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/google
for login - Set up CORS in your frontend to include credentials
- Use session cookies for authentication