dmitry-viskov/pylti1.3

Could not launch LTI tools successfully in Moodle

Opened this issue · 8 comments

Hi, when I try to launch the LTI tools (Both Flask and Django based) in Moodle (Deeplink was disabled). This error happens:

pylti1p3.exception.LtiServiceException: HTTP response [https://mymoodle.com/mod/lti/services.php/3/lineitems/36/lineitem/results?type_id=18]: 401
- {
    "status": 401,
    "reason": "Unauthorized",
    "request": {
        "method": "GET",
        "url": "/mod/lti/services.php/3/lineitems/36/lineitem/results?type_id=18",
        "accept": "application/vnd.ims.lis.v2.resultcontainer+json"
    }
}
[07/May/2024 05:04:55] "GET /api/scoreboard/lti1p3-launch-9222ced3-f1aa-4ad3-8043-c0ae5b258104/ HTTP/1.1" 500 75556

The scoreboards was empty and it cannot record students' score.

Also, after I enabled the Deep Link, I cannot launched the tools, which means I cannot even reach the game html. It returns 302, and cannot redirect into the tools.

I noticed that someone else have also got this similar error in Moodle. Can you help solve this, I've been stuck on this for weeks. :(

You have to enable access to the assignments and grades service when setting up the tool in Moodle.

You have to enable access to the assignments and grades service when setting up the tool in Moodle.

@hmoffatt Thanks for your reply. But I have enabled AGS service in tool setting.
屏幕截图 2024-05-07 195036

How about the key for your app then as configured in Moodle?

How about the key for your app then as configured in Moodle?
@hmoffatt
Here are my step:

  1. generate private/public key in Django app
    ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
    openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub

  2. Register the app in Moodle. At first I wanted to use keyset url, but it failed with Argument #1 ($jwks) must be of type array, null given, called in [dirroot]/mod/lti/locallib.php. Then I just copy the jwtRS256.key.pub into Moodle.

  3. Then I update the game.json in Django app, filling with the client ID, platform host, deployment id.... public_key_file,public_key_file

    "https://mymoodle.com": [{
        "default": true,
        "client_id": "5A5LH5RvaAkwfbU",
        "auth_login_url": "https://mymoodle.com/mod/lti/auth.php",
        "auth_token_url": "https://mymoodle.com/mod/lti/token.php",
        "auth_audience": null,
        "key_set_url": "https://mymoodle.com/mod/lti/certs.php",
        "key_set": null,
        "private_key_file": "jwtRS256.key",
        "public_key_file": "jwtRS256.key.pub",
        "deployment_ids": ["17"]
    }]
`https://mymoodle.com` is just an example, But I do run the moodle on public ip address in HTTPS.
  1. Trying to use the app in certain courses.

There are my full steps related to the key.

One day we had a similar issue and the problem was in Apache configuration that cut the Authorization header. See:
https://moodle.org/mod/forum/discuss.php?d=429186
https://stackoverflow.com/questions/17018586/apache-2-4-php-fpm-and-authorization-headers/17490827#17490827

One day we had a similar issue and the problem was in Apache configuration that cut the Authorization header. See: https://moodle.org/mod/forum/discuss.php?d=429186 https://stackoverflow.com/questions/17018586/apache-2-4-php-fpm-and-authorization-headers/17490827#17490827

@polesye Thanks! I'll give a try. Did you get this problem fixed with the solution in the link?

@besonn yes, I did. LTI tool provider sends grade back to the LMS via API endpoint that requires Authorization header. In our case, Apache just cut the header, so we experienced the error above. Adding SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 helps solve the issue.

@besonn yes, I did. LTI tool provider sends grade back to the LMS via API endpoint that requires Authorization header. In our case, Apache just cut the header, so we experienced the error above. Adding SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 helps solve the issue.

Thank you so much! I've solved this issue successfully !