Access username in xblock iframe


I’m new to open edx and I’m currently using edx platform to create a programming course. We put jupyterhub notebook link into iFrame xblock which allows the user to access, write and execute the code without manually logging into jupyterhub. Currently after several configurations on jupyterhub in another server, we are able to load jupyterhub properly.

However, another issue comes up. Since we need to provide a notebook URL when setting up the iframe, all users will access the same notebook and see each other’s work. We hope to give a unique jupyterhub notebook URL to each individual user, something like: jupyterhub/username/folder1/notebook1.ipynb. This design allows each user run their own notebook and be able to keep their notebook.

Is there any way to access username in cookies or API in iframe xblock, and programmatically put it in to iframe src?

Something like:
username = <“code to get username”>
<src = “” + username + “/folder/notebook1.ipynb”>

(sorry I had to add quotes in tags, otherwise we will see an empty iframe :P)
Any help or advice is much appreciated!

Hi @yipossible,

You could use the /api/user/v1/me API endpoint. It returns a JSON object containing the currently logged in user’s username.

Hi @yipossible,

If you are just putting the iframe into a standard HTML/Text component (perhaps using the “IFrame Tool” template), as suggested in the documentation, then there is an easy way:

Just put %%USER_ID%% anywhere in the HTML (e.g. in the iframe URL) where you’d like the user ID to appear (note that the user ID is unique for each course and user, so won’t be the same between courses). You can also use %%COURSE_ID%% for the course ID. Ref