This project demonstrates OAuth2 integration using Spring Boot and MySQL for the backend, and ReactJS for the frontend.
Before running the application, make sure to review and adjust the following configurations in the application.properties file.
In application.properties, update these values if needed:
spring.datasource.url=jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:oauth_demo}?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASS}- Replace
{DB_NAME}with your actual database name. - Update your MySQL username and password accordingly.
The following settings control the OAuth2 client credentials used for Google and GitHub login:
spring.security.oauth2.client.registration.google.client-id=${GOOGLE_CLIENT_ID}
spring.security.oauth2.client.registration.google.client-secret=${GOOGLE_CLIENT_SECRET}
spring.security.oauth2.client.registration.github.client-id=${GITHUB_CLIENT_ID}
spring.security.oauth2.client.registration.github.client-secret=${GITHUB_CLIENT_SECRET}The syntax ${VAR:default} means:
Use the environment variable
VARif available; otherwise, fall back to thedefaultvalue.
To configure these credentials, you have three options:
Keep the environment-variable placeholders in application.properties and set environment variables in your system or IDE (see next section).
Create a .env file in your project root:
DB_HOST=localhost
DB_PORT=3306
DB_NAME=oauth_demo
DB_USER=root
DB_PASS=password
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secretFor quick testing only, you can directly replace the variables with actual values in application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/oauth_demo?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=yourpassword
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-
Open Run → Edit Configurations...
-
Select your Spring Boot run configuration (or create one).
-
Locate the Environment variables field
-
Add your variables — either line by line or using the editor UI:
DB_HOST=localhost DB_PORT=3306 DB_NAME=oauth_demo DB_USER=root DB_PASS=password GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret GITHUB_CLIENT_ID=your-github-client-id GITHUB_CLIENT_SECRET=your-github-client-secret -
Click OK and Apply, then run your application.
- Open the
oauth2demobackend project in IntelliJ IDEA (This project was run on community edition). - Run the Spring Boot application — it will start on
http://localhost:8080.
- Open a terminal and navigate to the
oauth-demo-frontendfolder. - Install dependencies (if not already):
npm install - Start the frontend:
The React app will run on
npm starthttp://localhost:3000.
- Ensure that your MySQL database is created and accessible before running the backend.