The current env.development file of this MFE repo is for devstack so I changed the endpoints of this file to work with tutor dev: NODE_ENV='development' PORT=8080 ACCESS_TOKEN_COOKIE_NAME='edx-jwt-cookie-header-payload' BASE_URL='http://localhost:8080' STUDIO_BASE_URL='http://localhost:8001' LMS_BASE_URL='http://localhost:8000' CREDENTIALS_BASE_URL='http://localhost:1999' CSRF_TOKEN_API_PATH='/csrf/api/v1/token' ECOMMERCE_BASE_URL='http://localhost:18130' LANGUAGE_PREFERENCE_COOKIE_NAME='openedx-language-preference' LMS_BASE_URL='http://localhost:8000' LOGIN_URL='http://localhost:8000/login' LOGOUT_URL='http://localhost:8000/logout' LOGO_URL='https://edx-cdn.org/v3/default/logo.svg' LOGO_TRADEMARK_URL='https://edx-cdn.org/v3/default/logo-trademark.svg' LOGO_WHITE_URL='https://edx-cdn.org/v3/default/logo-white.svg' FAVICON_URL='https://edx-cdn.org/v3/default/favicon.ico' MARKETING_SITE_BASE_URL='http://localhost:8000' ORDER_HISTORY_URL='http://localhost:1996/orders' REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:8000/login_refresh' DATA_API_BASE_URL='http://localhost:8000' SEGMENT_KEY='' SITE_NAME=localhost USER_INFO_COOKIE_NAME='edx-user-info' APP_ID='' MFE_CONFIG_API_URL=''
Have you added the url to CORS_ORIGIN_WHITELIST setting in lms? Usually, this setting is needed so that the backend can process the request from the new client/app.
I’ve added it to the local Docker, but now I am attempting to run it outside (for an easier development phase) and trying to communicate with Docker.
I think I did not add the URL to the CORS_ORIGIN_WHITELIST setting in LMS. May I ask how to find this file? Because what I did to run the Tutor Docker (both locally and in development) was:
pip install "tutor[full]"
tutor local(dev) launch
So, I don’t know where to set up CORS_ORIGIN_WHITELIST.
Just to remind that I have successfully run the mfe with tutor local launch:
But it’s really painfull in the dev phase that I have to push the code to github master branch and rebuild the docker images just for small code change, so I have to figure out how to run it in dev.
So these are what I did to run in dev:
Launch the docker:
pip install “tutor[full]”
tutor dev launch
Right. So you are not using tutor-mfe to add a new MFE but rather running an MFE outside the containers and trying to connect it to tutor LMS? If that is the case, then you need to add localhost:8000 to CORS_ORIGIN_WHITELIST. This is because you are not using tutor-mfe plugin, which handled the addition to cors_whitelist automatically.
To add localhost:8000 to cors whitelist, you would need a custom tutor plugin where you would add lms and cms patches (Modifying edx-platform settings — Tutor documentation)
After bypassed the CORS, there is the /login_refresh that failed, how can I call it, this API is very important for me to get the current info, I have to call it.
You can see that, even if I have successfully logged in from the LMS but the avatar doesn’t appear, all because I failed to call /login_refresh api:
If you are logging in via LMS, it should automatically set the right session information in cookies.
If you are talking about JWT token especially, that is obtained from oauth2/access_token endpoint. But as far as I know, you don’t need to get that token for MFEs.
Also, what is the best practice for obtained the JWT, your suggestion oauth2/access_token endpoint is great but that’s means the user have to provide password again (one for logging to LMS, and one for my custom app):
@the_tan_Nguyen I am facing the same problem you had (getting 401 when calling /login_refresh) Were you able to resolve that? If yes, could you please share your solution here? FYI, I am also running the MFE outside the docker container like you did by creating a tutor plugin.
Thanks
No, I cannot resolve the 401 when calling /login_refresh when I run MFE outside tutor local. But if you integrate via tutor local launch then everything works.
But I understand you need a way for local dev so I have a way to work around.
@the_tan_Nguyen I thought there could be a solution to this as I might require the user to be logged in for my use case. But as you said that the 401 won’t go away when running the MFE outside, then I can rely on your solution of hardcoding the things for development purpose. Thanks for your response, I really appreciate it!
hi guys, for development im facing this issue with login_refresh api too, and the way i used to fix it and continue fast development, i get the cookie in some edx logged page with document.cookie in browser console, and in my local mfe i paste the cookie document.cookie = 'edx-jwt-cookie-header-payload=you_awesome_cookie'