|
74 | 74 | RECAPTCHA_SITE_KEY = '6LesBKsrAAAAADwwja7GKS33AEC7ktIuJlcYpBDf' |
75 | 75 | RECAPTCHA_SECRET_KEY = '6LesBKsrAAAAANii1CrJeF_C679-5vRMgGNC6htZ' |
76 | 76 |
|
| 77 | +# Microsoft OAuth Client (set via environment in production) |
| 78 | +MICROSOFT_CLIENT_ID = os.getenv('MICROSOFT_CLIENT_ID', '') |
| 79 | +MICROSOFT_CLIENT_SECRET = os.getenv('MICROSOFT_CLIENT_SECRET', '') |
| 80 | +MICROSOFT_TENANT_ID = os.getenv('MICROSOFT_TENANT_ID', 'common') |
| 81 | + |
77 | 82 | # ---------------- Secure Session Cookie Settings ---------------- |
78 | 83 | # These settings ensure cookies are securely transmitted over HTTPS and protected from JS and CSRF attacks |
79 | 84 | SESSION_COOKIE_SECURE = not DEBUG # Only allow HTTPS cookies in production |
80 | 85 | SESSION_COOKIE_HTTPONLY = True # Prevent access to session cookies via JavaScript |
81 | | -SESSION_COOKIE_SAMESITE = 'Strict' # Restrict cross-origin cookie sharing |
| 86 | +SESSION_COOKIE_SAMESITE = 'Lax' # Allow cross-origin cookie sharing for OAuth |
82 | 87 |
|
83 | 88 | CSRF_COOKIE_SECURE = not DEBUG # Ensure CSRF cookie is sent over HTTPS |
84 | 89 | CSRF_COOKIE_SAMESITE = 'Strict' # Restrict CSRF cookie from cross-origin requests |
85 | 90 |
|
86 | 91 | # ---------------- Idle Session Timeout Configuration ---------------- |
87 | 92 | # Automatically logs out users after 5 minutes of inactivity, resets on every user request |
88 | | -SESSION_COOKIE_AGE = 300 # 5 minutes in seconds |
| 93 | +SESSION_COOKIE_AGE = 1800 # 30 minutes in seconds |
89 | 94 | SESSION_SAVE_EVERY_REQUEST = True # Reset the session timeout on each request |
90 | | -SESSION_EXPIRE_AT_BROWSER_CLOSE = True # Expire session when browser closes |
| 95 | +SESSION_EXPIRE_AT_BROWSER_CLOSE = False # Keep session when browser closes |
91 | 96 | SESSION_ENGINE = 'django.contrib.sessions.backends.db' # Store sessions in DB |
92 | 97 |
|
93 | 98 | # Application definition |
|
106 | 111 | "django.contrib.staticfiles", |
107 | 112 | "django_extensions", |
108 | 113 | 'django_cron', |
109 | | - "django_user_agents", |
110 | 114 |
|
| 115 | + 'imagekit', |
| 116 | + "django_user_agents", |
111 | 117 | 'rest_framework', |
112 | 118 | 'drf_yasg', |
| 119 | + # Social Auth - Microsoft OAuth |
| 120 | + 'social_django', |
113 | 121 |
|
114 | 122 | 'home.apps.HomeConfig', |
115 | 123 | 'theme_pixel', |
|
132 | 140 | "django.contrib.auth.middleware.AuthenticationMiddleware", |
133 | 141 | "django.contrib.messages.middleware.MessageMiddleware", |
134 | 142 | # "home.idle.IdleTimeoutMiddleware", |
| 143 | + |
135 | 144 | "home.idle.LogoutMiddleware", |
136 | 145 | "django.middleware.clickjacking.XFrameOptionsMiddleware", |
137 | 146 | "home.ratelimit_middleware.GlobalLockoutMiddleware", |
138 | 147 |
|
139 | 148 | 'core.middleware.AutoLogoutMiddleware', |
140 | 149 |
|
141 | 150 | "home.admin_session_middleware.AdminSessionMiddleware", #admin session middleware |
| 151 | + |
| 152 | + # "home.idle.LogoutMiddleware", # TEMPORARILY DISABLED - causing OAuth redirect issues |
| 153 | + "django.middleware.clickjacking.XFrameOptionsMiddleware", |
| 154 | + # "home.ratelimit_middleware.GlobalLockoutMiddleware", # TEMPORARILY DISABLED - causing OAuth redirect issues |
| 155 | + # "home.admin_session_middleware.AdminSessionMiddleware", # TEMPORARILY DISABLED - causing OAuth redirect issues |
| 156 | + # 'core.middleware.AutoLogoutMiddleware', # TEMPORARILY DISABLED - causing OAuth redirect issues |
| 157 | + |
142 | 158 | "django_user_agents.middleware.UserAgentMiddleware", |
| 159 | + # "core.middleware.LogRequestMiddleware", # TEMPORARILY DISABLED - causing OAuth redirect issues |
| 160 | + # "home.views.force_oauth_redirect_middleware", # DISABLED - causing redirect loops |
143 | 161 |
|
144 | 162 |
|
145 | 163 | ] |
|
186 | 204 | "django.contrib.messages.context_processors.messages", |
187 | 205 | 'home.context_processors.dynamic_page_title', |
188 | 206 | 'home.context_processors.recaptcha_site_key', |
| 207 | + |
189 | 208 | 'home.context_processors.user_scores', |
| 209 | + |
| 210 | + 'home.context_processors.microsoft_client_id', |
| 211 | + 'social_django.context_processors.backends', |
| 212 | + 'social_django.context_processors.login_redirect', |
| 213 | + |
| 214 | + |
190 | 215 | ], |
191 | 216 | }, |
192 | 217 | }, |
|
327 | 352 |
|
328 | 353 | DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |
329 | 354 |
|
330 | | -LOGIN_REDIRECT_URL = '/' |
| 355 | +LOGIN_REDIRECT_URL = '/dashboard/' |
331 | 356 | EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' |
332 | 357 | EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' |
333 | 358 | EMAIL_HOST = 'smtp.gmail.com' |
|
352 | 377 | } |
353 | 378 |
|
354 | 379 |
|
| 380 | +# Authentication backends |
| 381 | +AUTHENTICATION_BACKENDS = ( |
| 382 | + 'django.contrib.auth.backends.ModelBackend', |
| 383 | + 'home.custom_azure_backend.CustomAzureADTenantOAuth2', |
| 384 | +) |
| 385 | + |
| 386 | +# Social Auth (Azure AD) |
| 387 | +SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY = MICROSOFT_CLIENT_ID |
| 388 | +SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET = MICROSOFT_CLIENT_SECRET |
| 389 | +SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID = MICROSOFT_TENANT_ID |
| 390 | +SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_REDIRECT_URI = 'http://localhost:8000/complete/azuread-tenant-oauth2/' |
| 391 | +SOCIAL_AUTH_REDIRECT_IS_HTTPS = False |
| 392 | +SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/dashboard/' |
| 393 | +# SOCIAL_AUTH_LOGIN_ERROR_URL = '/accounts/login/' # DISABLED TO PREVENT LOGIN REDIRECTS |
| 394 | +SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/dashboard/' |
| 395 | +SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/dashboard/' |
| 396 | +# SOCIAL_AUTH_DISCONNECT_REDIRECT_URL = '/accounts/login/' # DISABLED TO PREVENT LOGIN REDIRECTS |
| 397 | +SOCIAL_AUTH_STRATEGY = 'social_django.strategy.DjangoStrategy' |
| 398 | +SOCIAL_AUTH_STORAGE = 'social_django.models.DjangoStorage' |
| 399 | +SOCIAL_AUTH_RAISE_EXCEPTIONS = False |
| 400 | +SOCIAL_AUTH_SANITIZE_REDIRECTS = False |
| 401 | +SOCIAL_AUTH_RAISE_EXCEPTIONS = False |
| 402 | +SOCIAL_AUTH_USER_MODEL = 'home.User' |
| 403 | +SOCIAL_AUTH_CREATE_USERS = True |
| 404 | +SOCIAL_AUTH_ASSOCIATE_BY_EMAIL = True |
| 405 | +SOCIAL_AUTH_ALWAYS_ASSOCIATE = False |
| 406 | + |
| 407 | +# Ensure user is created and details saved, enforce Deakin rule |
| 408 | +SOCIAL_AUTH_PIPELINE = ( |
| 409 | + 'social_core.pipeline.social_auth.social_details', |
| 410 | + 'social_core.pipeline.social_auth.social_uid', |
| 411 | + 'social_core.pipeline.social_auth.auth_allowed', |
| 412 | + 'social_core.pipeline.social_auth.social_user', |
| 413 | + 'social_core.pipeline.user.get_username', |
| 414 | + 'social_core.pipeline.social_auth.associate_by_email', |
| 415 | + 'social_core.pipeline.user.create_user', |
| 416 | + 'social_core.pipeline.social_auth.associate_user', |
| 417 | + 'social_core.pipeline.social_auth.load_extra_data', |
| 418 | + 'social_core.pipeline.user.user_details', |
| 419 | + 'home.pipeline.check_deakin_email', |
| 420 | + 'home.pipeline.set_oauth_redirect_url', |
| 421 | + 'home.pipeline.ensure_user_authenticated', |
| 422 | +) |
| 423 | + |
355 | 424 | CACHES = { |
356 | 425 | 'default': { |
357 | 426 | 'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache', |
|
467 | 536 |
|
468 | 537 | # CORS configuration |
469 | 538 | CORS_ALLOWED_ORIGINS = [ |
470 | | - 'http://127.0.0.1:8000', # Website localhost server url |
| 539 | + 'http://localhost:8000', # Website localhost server url |
471 | 540 | 'https://hardhatwebdev2024.pythonanywhere.com', # Frontend url |
472 | 541 | ] |
473 | 542 |
|
|
488 | 557 |
|
489 | 558 | # ---------------- Idle Session Timeout Configuration ---------------- |
490 | 559 | # Automatically logs out users after 5 minutes of inactivity, resets on every user request |
491 | | -SESSION_COOKIE_AGE = 300 # 5 minutes in seconds |
| 560 | +SESSION_COOKIE_AGE = 1800 # 30 minutes in seconds |
492 | 561 | SESSION_SAVE_EVERY_REQUEST = True # Reset the session timeout on each request |
493 | | -SESSION_EXPIRE_AT_BROWSER_CLOSE = True # Expire session when browser closes |
| 562 | +SESSION_EXPIRE_AT_BROWSER_CLOSE = False # Keep session when browser closes |
494 | 563 | SESSION_ENGINE = 'django.contrib.sessions.backends.db' # Store sessions in DB |
495 | 564 |
|
496 | 565 |
|
|
961 | 1030 | # DATA_UPLOAD_MAX_NUMBER_FIELDS = 1000 |
962 | 1031 | # DATA_UPLOAD_MAX_MEMORY_SIZE = 10485760 # 10 MB |
963 | 1032 |
|
| 1033 | +DEBUG = True |
| 1034 | + |
| 1035 | + |
| 1036 | + |
964 | 1037 | SECURITY_EMAIL = "hardhatwebsite@gmail.com" |
965 | 1038 |
|
0 commit comments