Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user_id not set and send as expected #217

Open
sroertgen opened this issue Dec 21, 2021 · 13 comments
Open

user_id not set and send as expected #217

sroertgen opened this issue Dec 21, 2021 · 13 comments

Comments

@sroertgen
Copy link
Contributor

Hello 👋,

I am running the tutor distribution of Open Edx (https://docs.tutor.overhang.io/) and trying to add an LTI component.

I followed these steps: https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/lti_component.html#enabling-and-using-lti-advantage-features

For the LTI component I want to pass the edx username to the LTI component. So here https://my-edx.de/admin/xblock_config/courseeditltifieldsenabledflag/ I added the respective course, which gives me the opportunity to set the flag "Request user's username" to True in my course.

Following your guide to test LTI (https://github.com/edx/xblock-lti-consumer#lti-11) I always get user_id=student and not the current edx user. Am I still missing something here? What do I have to configure to get the current user passed on to my LTI component?

Thank you!

@giovannicimolin
Copy link
Contributor

giovannicimolin commented Dec 21, 2021

Hi @sroertgen,

Which release of the Open edX platform are you running?
On more recent versions, the PII WaffleFlag has been replaced by a unified flag for PII sharing (read more about it on Unified Flag for Enabling Sharing of PII in LTI (ADR)).

Can you try enabling that flag if it's available on your instance?

@sroertgen
Copy link
Contributor Author

Hello @giovannicimolin ,

thanks for the fast response! I'm running openedx:12.2.0 .

I added my course to CourseEditLTIFieldsEnabledFlag in the below depicted menu:

Screenshot 2021-12-21 at 15 13 16

That gave me the opportunity to set the ask_to_send_username flag to True.

Still I only get username=student.

@sroertgen
Copy link
Contributor Author

sroertgen commented Jan 4, 2022

Hello and a happy and successful new year!

Do you have some tips on debugging this issue? I'm quite new to openedx and still digging my way through.

If you have suggestions on how I can debug the LTI parameters and see where this goes wrong, I will be very grateful! Thank you!

@sroertgen
Copy link
Contributor Author

Looking at the studio logs, I get a lot deprecation warnings, so it might have something to do with that?
e.g.

edx.devstack.studio               | 2022-01-04 15:30:41,518 WARNING 610 [py.warnings] [user 3] [ip 172.25.0.1] warnings.py:109 - /edx/src/xblock-lti-consumer/lti_consumer/lti_xblock.py:884: DeprecationWarning: runtime.get_real_user is deprecated. Please use the user service instead.
edx.devstack.studio               |   if callable(self.runtime.get_real_user):
edx.devstack.studio               |
edx.devstack.studio               | 2022-01-04 15:30:41,543 WARNING 610 [py.warnings] [user 3] [ip 172.25.0.1] warnings.py:109 - /edx/src/xblock-lti-consumer/lti_consumer/lti_xblock.py:885: DeprecationWarning: runtime.get_real_user is deprecated. Please use the user service instead.
edx.devstack.studio               |   real_user_object = self.runtime.get_real_user(self.runtime.anonymous_student_id)
edx.devstack.studio               |
edx.devstack.studio               | 2022-01-04 15:30:41,546 WARNING 610 [py.warnings] [user 3] [ip 172.25.0.1] warnings.py:109 - /edx/src/xblock-lti-consumer/lti_consumer/lti_xblock.py:885: DeprecationWarning: runtime.anonymous_student_id is deprecated. Please use the user service instead.
edx.devstack.studio               |   real_user_object = self.runtime.get_real_user(self.runtime.anonymous_student_id)
edx.devstack.studio               |

Just thinking out loud here and further investigating...

@sroertgen
Copy link
Contributor Author

So i found out the following, changing these lines:

@property
def user_id(self):
"""
Returns the opaque anonymous_student_id for the current user.
"""
user_id = self.runtime.anonymous_student_id
if user_id is None:
raise LtiError(self.ugettext("Could not get user id for current request"))
return str(urllib.parse.quote(user_id))

to:

    @property
    def user_id(self):
        """
        Returns the opaque anonymous_student_id for the current user.
        """
        user_id = self.runtime.service(self, 'user').get_current_user().opt_attrs['edx-platform.user_id']
        if user_id is None:
            raise LtiError(self.ugettext("Could not get user id for current request"))
        return str(user_id)

gives me the current user_id as expected.

(Btw I find this user service is poorly documented. In the XBlock API documentation there is just the notice that runtime.user_id is deprecated in favour of a new user service, but no links to that service: https://edx.readthedocs.io/projects/xblock/en/latest/runtime.html#xblock.runtime.Runtime.user_id)

Some searching brought me here: https://github.com/openedx/XBlock/blob/master/xblock/reference/user_service.py where some properties are explained. Maybe I just the documentation part somewhere (please send it to me, if there is some :) )

@giovannicimolin
Copy link
Contributor

giovannicimolin commented Jan 7, 2022

Hi @sroertgen, sorry for the delay! I was on vacation for the past few weeks and I'm catching up now.
Happy new year!

I scheduled a ticket to look at this issue in my next sprint (starting Jan 11) and will get back to you once I start working on it.

@sroertgen
Copy link
Contributor Author

sroertgen commented Jan 8, 2022

Hey @giovannicimolin,

no problem! I hope you had a nice and relaxing time!

If you want to know, what I changed, here is my fork: https://github.com/sroertgen/xblock-lti-consumer/blob/master/lti_consumer/lti_xblock.py

Since I'm currently only interested in LTI1.1 I only changed the necessary parts to get that working.

Maybe worth to point out: I didn't know exactly, what you were meaning with opaque anonymous_student_id in your code. There seem to be two options to get a user_id from the new user service. Either a really anonymous one, which is always student. Or the user_id of the current edx-user, which is some integer (and what is what I use now).

@Alain1405
Copy link

We also encountered this issue on Maple.

@Alain1405
Copy link

Alain1405 commented Jan 12, 2022

If I understand this issue correctly, after reading Maple release note at https://edx.readthedocs.io/projects/open-edx-release-notes/en/latest/maple.html#lti-1-3-and-lti-advantage-support we have enabled admin/lti_consumer/courseallowpiisharinginltiflag/ for the course and now the user_id is sent properly to the tool.

@giovannicimolin
Copy link
Contributor

giovannicimolin commented Jan 14, 2022

@sroertgen

user_id = self.runtime.service(self, 'user').get_current_user().opt_attrs['edx-platform.user_id']

This is not the best approach since the method you are modifying is supposed to return the anonymous user id and not the actual user id used by the platform. You're right about the user service though, the parameter currently being used is deprecated, so the proper usage would be similar to what you've used:

user_id = self.runtime.service(self, 'user').get_current_user().opt_attrs['edx-platform.anonymous_user_id']

If you open a pull request with this change I can review and approve it. 😁

Following your guide to test LTI (https://github.com/edx/xblock-lti-consumer#lti-11) I always get user_id=student and not the current edx user. Am I still missing something here? What do I have to configure to get the current user passed on to my LTI component?
There seem to be two options to get a user_id from the new user service. Either a really anonymous one, which is always student. Or the user_id of the current edx-user, which is some integer (and what is what I use now).

You are probably testing your code using studio, the runtime on studio will always return student - since it's only a means for testing and not actually using the block.
If you used the same method in the LMS (either by clicking on Preview or "View Live") you'll receive the proper anonymous ID, see:

# This is on the LMS:
(Pdb) self.runtime.anonymous_student_id
'f8ecdecbae54d761637dfa15267bd996'

# This is on Studio:
(Pdb) self.runtime.anonymous_student_id
'student'

@giovannicimolin
Copy link
Contributor

@sroertgen Also, I checked your fork (diff here), and saw that you replaced the deprecated runtime methods with the new user service.

I can review those changes if you want to contribute them back to the platform.

@sroertgen
Copy link
Contributor Author

Hey @giovannicimolin ,

thanks for clarifying!

I will be happy to contribute them back and will prepare so (but it might take till the end of the week).

Just one more quick question (being new to edx): What is your recommended devstack, which you would also use for reviewing? Is it the Open edX devstack or is there something else you can recommend?

@giovannicimolin
Copy link
Contributor

giovannicimolin commented Jan 19, 2022

@sroertgen I personally use the Open edX devstack (https://github.com/openedx/devstack) - with a somewhat modified networking setup to test LTI 1.3 launches.
An alternative would be to use Tutor, but I never tested it as a development environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Enhancements and Fixes - In Progress
Development

No branches or pull requests

3 participants