This document shows exactly what should be configured in AWS CloudFront and Google Cloud Console for your JWT-based OAuth setup.
You have THREE CloudFront distributions:
sriinfosoft.com (S3 bucket) - NOT related to task manager apptaskmanager.sriinfosoft.com (React app on EC2)api-taskmanager.sriinfosoft.com (Spring Boot on EC2)This document covers configurations for distributions #2 and #3 only.
Purpose: Serve your React frontend application
taskmanager.sriinfosoft.com*.sriinfosoft.com)| Setting | Value |
|---|---|
| Origin domain | ec2-54-193-90-49.us-west-1.compute.amazonaws.com |
| Protocol | HTTP only |
| HTTP port | 80 |
| HTTPS port | 443 (not used) |
| Origin path | (leave empty) |
| Setting | Value |
|---|---|
| Path pattern | Default (*) |
| Viewer protocol policy | Redirect HTTP to HTTPS |
| Allowed HTTP methods | GET, HEAD, OPTIONS |
| Cache policy | CachingOptimized (or Managed-CachingOptimized) |
| Origin request policy | (none needed) |
| Response headers policy | (optional: CORS-with-preflight) |
Why these settings:
Purpose: Proxy API requests to your backend
api-taskmanager.sriinfosoft.com*.sriinfosoft.com)| Setting | Value |
|---|---|
| Origin domain | ec2-54-193-90-49.us-west-1.compute.amazonaws.com |
| Protocol | HTTP only |
| HTTP port | 8080 |
| HTTPS port | 443 (not used) |
| Origin path | (leave empty) |
| Keep-alive timeout | 60 seconds |
| Read timeout | 60 seconds |
| Setting | Value |
|---|---|
| Path pattern | Default (*) |
| Viewer protocol policy | Redirect HTTP to HTTPS |
| Allowed HTTP methods | GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE ⚠️ |
| Cache policy | CachingDisabled ⚠️ |
| Origin request policy | AllViewer ⚠️ |
| Response headers policy | (optional: CORS-with-preflight) |
Why these settings:
CachingDisabled - APIs should never be cachedAllViewer - Forwards ALL headers, cookies, query strings to backendIMPORTANT: Without CachingDisabled and AllViewer, your API will not work properly!
You have THREE DNS records in your sriinfosoft.com hosted zone:
sriinfosoft.com → S3 CloudFront distributiontaskmanager.sriinfosoft.com → Task Manager Frontend CloudFrontapi-taskmanager.sriinfosoft.com → Task Manager Backend CloudFrontThis document covers configurations for #2 and #3 only.
Record name: taskmanager
Type: A - Routes traffic to an IPv4 address and some AWS resources
Alias: ON (enabled)
Route traffic to: Alias to CloudFront distribution
Choose Region: US East (N. Virginia) [us-east-1]
Choose endpoint: [Your FRONTEND CloudFront distribution]
Routing policy: Simple routingFull domain: taskmanager.sriinfosoft.com
Record name: api-taskmanager
Type: A - Routes traffic to an IPv4 address and some AWS resources
Alias: ON (enabled)
Route traffic to: Alias to CloudFront distribution
Choose Region: US East (N. Virginia) [us-east-1]
Choose endpoint: [Your BACKEND CloudFront distribution]
Routing policy: Simple routingFull domain: api-taskmanager.sriinfosoft.com
Add BOTH domains:
https://taskmanager.sriinfosoft.com
https://api-taskmanager.sriinfosoft.comRules:
https:// (not http://)localhost or EC2 direct URLsWhy both domains:
taskmanager.sriinfosoft.com - Frontend initiates OAuth requestsapi-taskmanager.sriinfosoft.com - Backend makes API calls to GoogleAdd ONLY ONE URI:
https://taskmanager.sriinfosoft.com/login/oauth2/code/googleRules:
/login/oauth2/code/googleWhy frontend URL:
https://taskmanager.sriinfosoft.com
https://api-taskmanager.sriinfosoft.com(2 origins)
https://taskmanager.sriinfosoft.com/login/oauth2/code/google(1 redirect URI - frontend only)
Screenshot reference:
┌─────────────────────────────────────────────────────────┐
│ OAuth 2.0 Client ID │
├─────────────────────────────────────────────────────────┤
│ Authorized JavaScript origins │
│ ┌─────────────────────────────────────────────────┐ │
│ │ https://taskmanager.sriinfosoft.com │ │
│ └─────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────┐ │
│ │ https://api-taskmanager.sriinfosoft.com │ │
│ └─────────────────────────────────────────────────┘ │
│ │
│ Authorized redirect URIs │
│ ┌─────────────────────────────────────────────────┐ │
│ │ https://taskmanager.sriinfosoft.com/login/ │ │
│ │ oauth2/code/google │ │
│ └─────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘| Type | Protocol | Port Range | Source | Description |
|---|---|---|---|---|
| SSH | TCP | 22 | Your IP | SSH access |
| HTTP | TCP | 80 | 0.0.0.0/0 | Frontend (CloudFront) |
| Custom TCP | TCP | 8080 | 0.0.0.0/0 | Backend API (CloudFront) |
Note:
Key configuration for JWT-based OAuth:
# CORS - Allow frontend domain
cors.allowed-origins=${FRONTEND_URL:https://taskmanager.sriinfosoft.com}
# OAuth redirect goes to FRONTEND
spring.security.oauth2.client.registration.google.redirect-uri=${FRONTEND_URL:https://taskmanager.sriinfosoft.com}/login/oauth2/code/googleNOT:
# ❌ WRONG - Do not use backend domain for redirect
spring.security.oauth2.client.registration.google.redirect-uri=https://api-taskmanager.sriinfosoft.com/login/oauth2/code/googleFRONTEND_URL=https://taskmanager.sriinfosoft.com
# No BACKEND_URL needed for OAuth redirectNOT:
# ❌ Don't use BACKEND_URL for OAuth redirect
BACKEND_URL=https://api-taskmanager.sriinfosoft.com❌ Remove from Authorized redirect URIs:
https://api-taskmanager.sriinfosoft.com/login/oauth2/code/google❌ Remove any localhost URLs:
http://localhost:3000http://localhost:8080/login/oauth2/code/google✅ Keep ONLY:
https://taskmanager.sriinfosoft.com/login/oauth2/code/google❌ Remove any session cookie configurations:
# These are NOT needed for JWT-based OAuth
server.servlet.session.cookie.domain=.sriinfosoft.com
server.servlet.session.cookie.secure=true
server.servlet.session.cookie.same-site=none
server.forward-headers-strategy=framework✅ Keep simple JWT configuration:
jwt.secret=${JWT_SECRET}
jwt.expiration=86400000
spring.security.oauth2.client.registration.google.redirect-uri=${FRONTEND_URL}/login/oauth2/code/google❌ Remove from backend environment:
- BACKEND_URL=${BACKEND_URL} # Not needed for OAuth✅ Keep these:
environment:
- FRONTEND_URL=${FRONTEND_URL}
- JWT_SECRET=${JWT_SECRET}
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}❌ Remove:
BACKEND_URL=http://taskmanager-backend:8080
BACKEND_URL=https://api-taskmanager.sriinfosoft.com✅ Keep:
FRONTEND_URL=https://taskmanager.sriinfosoft.com
JWT_SECRET=your-secret
GOOGLE_CLIENT_ID=your-id
GOOGLE_CLIENT_SECRET=your-secret
DB_PASSWORD=your-passwordAfter making changes, verify:
taskmanager.sriinfosoft.comapi-taskmanager.sriinfosoft.comCachingDisabledAllViewertaskmanager A record → Frontend CloudFrontapi-taskmanager A record → Backend CloudFronttaskmanager.sriinfosoft.com/login/oauth2/code/google)redirect-uri uses ${FRONTEND_URL}/login/oauth2/code/googleBACKEND_URL in backend environment variablesJWT_SECRET configured in .env# Test frontend
curl -I https://taskmanager.sriinfosoft.com
# Should return: 200 OK
# Test backend API
curl https://api-taskmanager.sriinfosoft.com/actuator/health
# Should return: {"status":"UP"}https://taskmanager.sriinfosoft.comhttps://taskmanager.sriinfosoft.com/login/oauth2/code/google?code=...taskmanager.sriinfosoft.com):api-taskmanager.sriinfosoft.com):❌ Mistake 1: Using backend URL for OAuth redirect
# WRONG
redirect-uri=https://api-taskmanager.sriinfosoft.com/login/oauth2/code/google❌ Mistake 2: Adding session cookie config with JWT
# WRONG - Not needed with JWT
server.servlet.session.cookie.domain=.sriinfosoft.com❌ Mistake 3: Not setting CloudFront cache policy correctly
# WRONG - API responses will be cached
Cache policy: CachingOptimized (for backend API)
# RIGHT
Cache policy: CachingDisabled (for backend API)❌ Mistake 4: Forgetting to allow all HTTP methods for API
# WRONG - Only GET, HEAD, OPTIONS
Allowed methods: GET, HEAD, OPTIONS
# RIGHT - All methods for REST API
Allowed methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE❌ Mistake 5: Using trailing slashes in Google Console
# WRONG
https://taskmanager.sriinfosoft.com/
# RIGHT
https://taskmanager.sriinfosoft.com| Component | Configuration | Value |
|---|---|---|
| CloudFront Frontend | CNAME | taskmanager.sriinfosoft.com |
| Origin Port | 80 | |
| Cache Policy | CachingOptimized | |
| CloudFront Backend | CNAME | api-taskmanager.sriinfosoft.com |
| Origin Port | 8080 | |
| Cache Policy | CachingDisabled | |
| Origin Request | AllViewer | |
| Methods | All (GET, POST, PUT, DELETE, etc.) | |
| Route 53 | Frontend | A record → Frontend CloudFront |
| Backend | A record → Backend CloudFront | |
| Google OAuth | JavaScript Origins | Both domains |
| Redirect URI | Frontend domain only | |
| application.properties | redirect-uri | ${FRONTEND_URL}/login/oauth2/code/google |
| cors.allowed-origins | ${FRONTEND_URL} | |
| Environment | FRONTEND_URL | https://taskmanager.sriinfosoft.com |
| BACKEND_URL | Not used for OAuth | |
| JWT_SECRET | Generated base64 string |
This is your complete reference. Follow these exact configurations and your OAuth should work correctly with the JWT-based flow.