Skip to content

Commit 068ae72

Browse files
committed
Force real OAuth in production regardless of USE_DEX_OAUTH setting
In production mode (ENV_TYPE=production), always use real GitHub and Google OAuth services. This bypasses any potential issues with the USE_DEX_OAUTH environment variable not being parsed correctly. Development mode still supports Keycloak mock OAuth when explicitly enabled. This ensures production doesn't accidentally use the mock OAuth service.
1 parent f57d1e1 commit 068ae72

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

papers2code_app2/routers/auth_routes.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,27 @@
3131

3232
auth_service = AuthService()
3333

34-
# Initialize OAuth services based on configuration
35-
# If USE_DEX_OAUTH is True, use Keycloak for both GitHub and Google OAuth (development)
36-
# Otherwise, use real GitHub and Google OAuth services (production)
37-
if config_settings.USE_DEX_OAUTH:
34+
# Initialize OAuth services based on configuration and environment
35+
# In PRODUCTION, ALWAYS use real GitHub and Google OAuth regardless of USE_DEX_OAUTH
36+
# In DEVELOPMENT, use Keycloak only if explicitly enabled
37+
is_production = config_settings.ENV_TYPE == "production"
38+
39+
if is_production:
40+
# PRODUCTION: Always use real OAuth services
41+
github_oauth_service = GitHubOAuthService()
42+
google_oauth_service = GoogleOAuthService()
43+
logger.info("PRODUCTION MODE: Using real GitHub and Google OAuth services")
44+
elif config_settings.USE_DEX_OAUTH:
45+
# DEVELOPMENT with Keycloak: Use mock OAuth
3846
from ..services.keycloak_oauth_service import keycloak_oauth_service
3947
github_oauth_service = keycloak_oauth_service
4048
google_oauth_service = keycloak_oauth_service
41-
logger.info("Using Keycloak OAuth service for development (USE_DEX_OAUTH=true)")
49+
logger.info("DEVELOPMENT MODE: Using Keycloak OAuth service (USE_DEX_OAUTH=true)")
4250
else:
51+
# DEVELOPMENT without Keycloak: Use real OAuth
4352
github_oauth_service = GitHubOAuthService()
4453
google_oauth_service = GoogleOAuthService()
45-
logger.info("Using real GitHub and Google OAuth services (USE_DEX_OAUTH=false)")
54+
logger.info("DEVELOPMENT MODE: Using real GitHub and Google OAuth services (USE_DEX_OAUTH=false)")
4655

4756
@router.get("/csrf-token", response_model=CsrfToken)
4857
async def get_csrf_token(request: Request, response: Response):

0 commit comments

Comments
 (0)