How to access user info from the javascript code

208 views
Skip to first unread message

Zoran Jeremic

unread,
Dec 28, 2015, 7:04:28 AM12/28/15
to General Open edX discussion
Hi,

I'm newbie to Open Edx. I'm developing a client side javascript code that should be embedded in the Course Info html content, or somewhere else, so it can be triggered after the student login for the first time and open a form with additional data that he needs to provide. This should be connected with remote nodejs server. The problem is how to identify user, i.e. to get his username or id, so I can create his profile on the remote server. I know I could get this information from the cookies, but I was hoping that there is some better and cleaner way.
I hope somebody could suggest best approach for this problem.

Thanks,
Zoran

Peter Pinch

unread,
Dec 29, 2015, 9:29:42 AM12/29/15
to edx-...@googlegroups.com
Hi Zoran. I've been trying to find some documentation for this, but no luck. We sometimes use a template token %%USER_ID%% in the courseware which gets replaced with an anonymous user id.

However, if you want to do this a more robust way (or if you need non-anonymous user data) you should look into LTI:

http://edx.readthedocs.org/projects/open-edx-building-and-running-a-course/en/latest/exercises_tools/lti_component.html

https://www.imsglobal.org/activity/learning-tools-interoperability

- Peter
Peter Pinch | Associate Director of Engineering, Office of Digital Learning
Massachusetts Institute of Technology
One Main Street | Cambridge MA 02142
E pdp...@mit.edu | T 617-253-6256 | C 617-652-0183






Zoran Jeremic

unread,
Dec 29, 2015, 12:50:32 PM12/29/15
to General Open edX discussion
Hi Peter,

Thank you for your quick response. I've been developing and using LTI earlier, but only in it's typical scenario, e.g. student click launch button to open external tool. However, the scenario I need to cover now is different, and I'm wondering if LTI might be used for that.
I need to integrate three different environments, so students could jump from one environment to the other on button click without having to register and login in each environment. Implementing Single-Sign-On would be ideal solution here. However, Edx is the main obstacle, since it should run in the MOOC on edx.org, so I don't have any control of it. I can't customize platform, create x-block or use third-party authentication, and I'm sure that I can only add custom javascript without permission of EDX support team. Anything else would have to go through the long procedure of getting approval from EDX team, and might not be finished before the MOOC should start.

After your proposal for using LTI, I started to think if it is possible to use it in a non-typical scenario. For example, I have custom LTI consumer implemented in the javascript and connected to the LTI producer on the other platform without any user action, so this connection is established in the background and user is not aware of that, and doesn't even have any external activity opened in Edx. He will have a button that will make it possible for him to be redirected to the other platform and use the account that was created through the LTI producer.

Do you think this scenario is realistic? If so, how could this work with three platforms?

Thanks,
Zoran

Peter Pinch

unread,
Dec 30, 2015, 10:48:35 AM12/30/15
to edx-...@googlegroups.com
From my understanding, it's actually pretty common to use LTI solely for authentication. Services like vitalsource use it to present copyrighted content (like textbooks) in various LMS. 

There's no need to use JavaScript in edX in this scenario. If you haven't already you should look at the LTI component. All you need is a shared secret and a URL. 

Without knowing more about the multiple services you are using, it's hard for me to speculate about authentication. You could authenticate through LTI to each external service individually, or you could authenticate to one LTI app that authenticates your user to all the other services. 

Hope this helps, 
Peter


--
You received this message because you are subscribed to the Google Groups "General Open edX discussion" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/edx-code/4c9a5442-208c-4b4e-ba21-9551f03b8292%40googlegroups.com.

Zoran Jeremic

unread,
Jan 7, 2016, 10:08:08 PM1/7/16
to General Open edX discussion
Hi Peter,

Thanks for this proposal.


Without knowing more about the multiple services you are using, it's hard for me to speculate about authentication. You could authenticate through LTI to each external service individually, or you could authenticate to one LTI app that authenticates your user to all the other services.

I'm investigating right now this as an option and I'm trying to make a simple working example. One of the services will probably be WordPress and the other one is custom made environment where I'm one of the developers. The second one has LTI 2.0 provider and LTI 1.1 consumer implemented.  I thought about developing NodeJS application that will run in the background between all three environments and which will also work for authentication between services.

I'm still not sure how it would work and how I can make three different environments to recognize user as a single entity. The scenario I need to cover here should replace Single-Sign-On, so the user could login to WordPress initially, click on the button there to jump to EdX, and click on the button to jump to third environment with only one account that he created in WordPress or EdX. If three environments have three LTI consumers connected with LTI producer on NodeJS, and user login to WordPress, his account will be created on the NodeJS through the connection with LTI Provider, but how can I redirect user to EdX and create his account there? I would need to have LTI consumer on NodeJS and LTI provider on EdX, right? This sounds too complicated.

Thanks,
Zoran
Reply all
Reply to author
Forward
0 new messages