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.

| Rounded Professional Program

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):


Lines Added/Enabled to Solve the CORS Issue

yaml

CopyEdit

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

Lines Added/Enabled to Solve the CSRF Trust Issue

yaml

CopyEdit

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

Same Settings Specifically for LMS (Must Match)

yaml

CopyEdit

LMS_CORS_ALLOW_CREDENTIALS: trueLMS_CORS_ORIGIN_WHITELIST:- http://localhost:1999- https://rp2masters.duckdns.orgLMS_CSRF_TRUSTED_ORIGINS:- http://localhost:1999- https://rp2masters.duckdns.org

Enabled AuthN MFE and Local Development

yaml

CopyEdit

ENABLE_AUTHN_MFE: trueENABLE_COMBINED_LOGIN_REGISTRATION: trueMFE_AUTHN_URL: http://localhost:1999MFE_DEV_MODE: trueMFE_PORT: 1999

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

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


Lines Added/Enabled to Solve the CORS Issue

yaml

CopyEdit

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

Lines Added/Enabled to Solve the CSRF Trust Issue

yaml

CopyEdit

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

Same Settings Specifically for LMS (Must Match)

yaml

CopyEdit

LMS_CORS_ALLOW_CREDENTIALS: trueLMS_CORS_ORIGIN_WHITELIST:- http://localhost:1999- https://rp2masters.duckdns.orgLMS_CSRF_TRUSTED_ORIGINS:- http://localhost:1999- https://rp2masters.duckdns.org

Enabled AuthN MFE and Local Development

yaml

CopyEdit

ENABLE_AUTHN_MFE: trueENABLE_COMBINED_LOGIN_REGISTRATION: trueMFE_AUTHN_URL: http://localhost:1999MFE_DEV_MODE: trueMFE_PORT: 1999

Mounted Your Local MFE App

yaml

CopyEdit

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

Is this the same post as How to resolve CORS error and 401 error ?