Unauthorized request while syncing Grades

Unauthorized request while syncing Grades

by Manos Garefalakis -
Number of replies: 6

Hello team, 
some help would be realy appreciated!

I am developing an external tool, using pylti1p3 (https://github.com/dmitry-viskov/pylti1.3).
I have managed to launch the tool from the Moodle (3.11 and 4.1), but when the tool tries to read the Grades of the activity I get an "Unauthorized request" error.

The tool gets the Bearer Token, but from this point I can't figure out what is the problem.
I have tried to simulate the tool using Postman, but I get the same error

{ "status": 401, "reason": "Unauthorized", "request": { "method": "GET", "url": "/moodle311/mod/lti/services.php/2/lineitems?type_id=3", "accept": "*/*" } }

Colud someone assist me with some suggestions?

Thanks in advance

 

Average of ratings: -
In reply to Manos Garefalakis

Re: Unauthorized request while syncing Grades

by Jake Dallimore -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Manos,

I'd first check that the service is enabled on the pre-configured tool (Site admin > External tool > manage tools > edit tool settings). There's a "Services" section in the form which contains "IMS LTI Assignment and Grade Services" which must be set to "Use this service for grade sync and column management". If this isn't set, then you won't be able to access those services. Then, the only other thing to make sure is that you're requesting the token with the relevant scope.

Hope that helps,
Jake
In reply to Jake Dallimore

Απάντ: Re: Unauthorized request while syncing Grades

by Manos Garefalakis -

Hello Jake,
thanks for the reply.

I made a test with the "IMS LTI Assignment and Grade Services" enabled and disabled.
The library checks and replies if the service is enabled or not.

As far the scopes, the bearer token is based on the following scopes

these are the scopes that the token is acquired

 'scope': ['https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
                'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
                'https://purl.imsglobal.org/spec/lti-ags/scope/score']} 


In reply to Manos Garefalakis

Re: Απάντ: Re: Unauthorized request while syncing Grades

by Jake Dallimore -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Manos,

It sounds like you've got it configured correctly and are using the correct scopes, so I'm out of the obvious ideas. That request to the lineitems service is probably throwing the 401 here:
https://github.com/moodle/moodle/blob/6f85c23d7f78620843cc274f296066365eae1158/mod/lti/service/gradebookservices/classes/local/resources/lineitems.php#L87

As to why, well, there could be a few reasons, but you'll need to debug Moodle's service code to find out which check is resulting in that 401.

Cheers
In reply to Jake Dallimore

Απάντ: Re: Απάντ: Re: Unauthorized request while syncing Grades

by Manos Garefalakis -
Hi Jake,
I saw your reply to another post, related to the moodle database.
I did a search to my database and I found these tables related to lti.
They are all empty....
Can this be related to my problem? Meaning that the endpoint for lineitems don't exist?
Thanks in advance

moodle database tables related to lti

In reply to Manos Garefalakis

Re: Απάντ: Re: Απάντ: Re: Unauthorized request while syncing Grades

by Jake Dallimore -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Manos,

These are definitely not related to the problem you're seeing with External tool, no. These are tables from an entirely different plugin (one which lets Moodle act as an LTI tool).

The best suggestion I can give right now, is to debug the request in the Moodle site, probably starting at mod/lti/services.php and stepping through the code there as the request comes in.

Cheers

In reply to Jake Dallimore

Απάντ: Re: Απάντ: Re: Απάντ: Re: Unauthorized request while syncing Grades

by Manos Garefalakis -
Hi Jake,
thanks for the reply.
The tool works on another moodle platform.
We are comparing the differences of the platforms.
The working platform has Moodle 4.06 and my platform, the non working has Moodle 4.1+
Except from installing Moodle 4.06, anything else that I should compare?
Like the php version? served by Apache or nginx?
Thanks in advance.