How to resolve CORS error and 401 error

I’m currently encountering an issue while working on the login functionality in our local development environment. Specifically, I’m trying to refresh the login session from the frontend running at http://localhost:1999, but the request to the backend server (https://rp2masters.duckdns.org) is being blocked.

Here’s what I’ve observed:

  • The frontend is attempting to refresh login from http://localhost:1999.
  • The backend server (rp2masters.duckdns.org) is not accepting requests from this origin.
  • As a result, I’m receiving a 401 Unauthorized response along with a CORS (Cross-Origin Resource Sharing) error in the browser console.

Here are the exact lines from my config.yml that i enabled or added to solve the CORS and CSRF-related issue between my local MFE (localhost:1999) and my backend (rp2masters.duckdns.org):


:white_check_mark: Lines Added/Enabled to Solve the CORS Issue

yaml

CopyEdit

CORS_ALLOW_CREDENTIALS: true
CORS_ORIGIN_WHITELIST:
- http://localhost:1999
- https://rp2masters.duckdns.org

:white_check_mark: Lines Added/Enabled to Solve the CSRF Trust Issue

yaml

CopyEdit

CSRF_TRUSTED_ORIGINS:
- http://localhost:1999
- https://rp2masters.duckdns.org

:white_check_mark: Same Settings Specifically for LMS (Must Match)

yaml

CopyEdit

LMS_CORS_ALLOW_CREDENTIALS: true
LMS_CORS_ORIGIN_WHITELIST:
- http://localhost:1999
- https://rp2masters.duckdns.org
LMS_CSRF_TRUSTED_ORIGINS:
- http://localhost:1999
- https://rp2masters.duckdns.org

:white_check_mark: Enabled AuthN MFE and Local Development

yaml

CopyEdit

ENABLE_AUTHN_MFE: true
ENABLE_COMBINED_LOGIN_REGISTRATION: true
MFE_AUTHN_URL: http://localhost:1999
MFE_DEV_MODE: true
MFE_PORT: 1999

:white_check_mark: Mounted my Local MFE App

yaml

CopyEdit

MOUNTS:
- mfe:/home/azureuser/.local/share/tutor-plugins/mfe/frontend-app-authn:/openedx/app/mfe/frontend-app-authn