LTi consumer simple php example

LTi consumer simple php example

by Nigel Hoath -
Number of replies: 11

Hi.  I need to get some sort of proof of concept up and running for my client.  As part of that I have a Moodle 3.1 set up with some single activity SCORMs.  I've loaded the LTi Provider plug in.

What I need now is some simple php code to pass some parameters (e.g secret, userid) to my Moodle to establish contact (nothing complex but if by the end of the weekend (I suspect for me a very long weekend) I could display a SCORM in an iframe wide eyes ).  I found one example but it appears out of date and not with any documentation I could find.

If anyone could point me to such a resource I'd be very grateful.  Tx in anticipation.






Average of ratings: -
In reply to Nigel Hoath

Re: LTi consumer simple php example

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Hello there. Sorry I'm not too sure about what you mean to do (and if it is about coding, programming I'm afraid I can't help) but you say you are using 3.1 and you have "loaded the LTI provider plugin" I presume you mean you have enabled Publish as LTI tool (docs link) because this is now standard in Moodle 3.1


In reply to Mary Cooch

Re: LTi consumer simple php example

by Nigel Hoath -

Mary yes it is sort of programming.

I have Moodle 3.1 set up as a LTi provider and using a test tool (e,g. LTi Launcher for Windows by Stephen Vickers) I can get an iframe connection to Moodle 1) inviting login and 2) directly and transparently logging in my admin user.  So the communication works in both directions.

I need to investigate various combinations of parameters (requests from the consumer) to get the user not only logged on but at the requested course/resource and then at the point the user last was at within the course/resource.

Why?  Well my LTi consumer is a non LTi compliant bespoke LMS so we need to code the communications at the consumer end.   And a simple php template and some example parameter combinations would be great  rather than reading the entire LTi specification which is probably beyond me even if I had more than a couple of days thoughtful

But glad I'm not the only one burning the weekend oil.  Tx and enjoy

In reply to Nigel Hoath

Re: LTi consumer simple php example

by Ken Task -
Picture of Particularly helpful Moodlers

"LTi consumer is a non LTi compliant bespoke LMS" ... so that means this other LMS doesn't have an LTI tool to access the LTI content you've setup in a Moodle 3.1 (you've tested accessing with some outside of Moodle tool and the LTI content in the 3.1 Moodle is being displayed, etc.).   Is that right so far?

If so, Moodle doesn't provide the code (API) for an LTI client (another LMS system).   For that, one would have to build one for the LMS that doesn't have an LTI tool.

Here's a page that shows various LMS's that have the tool:

http://www.edu-apps.org/tutorials.html

and here's a page that talks about how to build an app:

http://www.edu-apps.org/code.html

So, if you don't mind me asking, what is this other "bespoke LMS"?

Just for demo purposes, couldn't you acquire a free Canvas LMS account and do an LTI link to your Moodle 3.1?

'spirit of sharing', Ken

In reply to Ken Task

Re: LTi consumer simple php example

by Nigel Hoath -

Ken

Yes that is about it.  For sure I can demo launching my Moodle 3.1 in an iframe using a LTi testing tool.  What I haven't managed is to get that tool to not only log the user on but also position them in a course/resource.  But the weekend is not over yet wide eyes

However rather than a tool I would like to demo some code that acts as the LTi consumer (at a very simple level).  I found some php code that looked like it would do the job but maybe it was a bit out of date or whatever.  Thus the request.

While adding the LTi consumer functionality to a bespoke LMS may seem a bit of effort:

  • the current bespoke LMS contains 1000s of courses that are fully and seemlessly integrated into production systems.  Only new courses will go to Moodle.
  • the bespoke LMS is fully suported with an ongoing development team.
  • the Moodle is very simple in what it will do.  It will only have single activity SCORMs available to all 6000 users (no other resources).  The courses will be available as and when.  The bespoke LMS will enrol the users using Moodle web service.  It is not necessary for the LTi to be concerned with results/grades/completion.

For sure Moodle might play a bigger role over time but it needs to get its foot in the door.

Sorry wittering.

Anyway in the absense of a tool to show me the message/POST/XML formats I'll continue with the tools I have and use a network sniffer to have a look (although tired eyes says that will be tomorrow) sleepy


Unless someone knows of a tool/code out there???

Cheers and thanks Ken.




In reply to Nigel Hoath

Re: LTi consumer simple php example

by Ken Task -
Picture of Particularly helpful Moodlers

So bespoke is like a SCORM package ... online.   Bespoke itself doesn't have anything LTI yet (hmmmmm).

Should give others a chance to respond as they might know, but this being a holiday weekend in USA those folks, if observing the holiday, probably aren't gonna respond this weekend.    Thought you were under time crunch.

AnyHoo ....

How about this:

http://ltiapps.net/test/tc.php

So what if one put a bespoke package (it's a SCORM like package, right?) into another moodle 3.1 instance (as a course) and then from the demo moodle link to that resource using LTI.

'spirit of sharing', Ken



In reply to Ken Task

Re: LTi consumer simple php example

by Nigel Hoath -

Sorry Ken I must be leading you astray.  The bespoke LMS is an inhouse developed .net LMS embedded within production systems.  What it lacks are:

SCORM handling and LTi. 

But soon there will be a large number of new SCORM courses arriving.  So how can we give access to the SCORM packages without the users seeing two LMSs?  And LTi seems perfect in that it is a standard, accepted and documented approach.  We could just skip LTi and develop some code ourselves but we are not interested in long term support so the more we stick to industry standards the better.

There is an option to embed a SCORM engine within the current LMS but Moodle is a preferred approach when looking long term.

Well I hope you and the other good folks who hang around here enjoy your holiday.  cool




In reply to Nigel Hoath

Re: LTi consumer simple php example

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hello again - I'm not in the US (in the UK) so I'm not on holiday smile but as I said before, I'm afraid I can't help with coding. I am however surprised that there is a fully developed production LMS that doesn't support SCORM and LTI. I assumed most other LMSs did (only knowing Moodle)

Anyway, I have moved this thread to the LTI forum to see if you get more specialised advice.

In reply to Mary Cooch

Re: LTi consumer simple php example

by Nigel Hoath -

Thanks Mary smile

In reply to Nigel Hoath

Re: LTi consumer simple php example

by Nigel Hoath -

Well here a piece of php that sends a LTi POST.  It always launches Moodle 3.1.  It will log the session into admin if another session for admin already exists.  But not always. 

Just in case anyone can give any pointers here it is:

<?php
# ------------------------------
# START CONFIGURATION SECTION
#
$launch_url = "http://localhost";
$key = "E2SystemsConsumerKey";
$secret = "63736373";
$launch_data = array(
        "user_id" => "2",
        "roles" => "1",
);
#
# END OF CONFIGURATION SECTION
# ------------------------------
date_default_timezone_set("Europe/London");
$now = new DateTime();
$launch_data["lti_version"] = "LTI-1p0";
$launch_data["lti_message_type"] = "basic-lti-launch-request";
# Basic LTI uses OAuth to sign requests
# OAuth Core 1.0 spec: http://oauth.net/core/1.0/
$launch_data["oauth_callback"] = "about:blank";
$launch_data["oauth_consumer_key"] = $key;
$launch_data["oauth_version"] = "1.0";
$launch_data["oauth_nonce"] = uniqid('', true);
$launch_data["oauth_timestamp"] = $now->getTimestamp();
$launch_data["oauth_signature_method"] = "HMAC-SHA1";
# In OAuth, request parameters must be sorted by name
$launch_data_keys = array_keys($launch_data);
sort($launch_data_keys);
$launch_params = array();
foreach ($launch_data_keys as $key) {
  array_push($launch_params, $key . "=" . rawurlencode($launch_data[$key]));
}
$base_string = "POST&" . urlencode($launch_url) . "&" . rawurlencode(implode("&", $launch_params));
$secret = urlencode($secret) . "&";
$signature = base64_encode(hash_hmac("sha1", $base_string, $secret, true));
?>

<html>
<head></head>
<!-- <body onload="document.ltiLaunchForm.submit();"> -->
<body>
<form id="ltiLaunchForm" name="ltiLaunchForm" method="POST" action="<?php printf($launch_url); ?>">
<?php foreach ($launch_data as $k => $v ) { ?>
        <input type="hidden" name="<?php echo $k ?>" value="<?php echo $v ?>">
<?php } ?>
        <input type="hidden" name="oauth_signature" value="<?php echo $signature ?>">
        <button type="submit">Launch</button>
</form>
<body>
</html>


In reply to Nigel Hoath

Re: LTi consumer simple php example

by Nigel Hoath -

Just to say cooking with gas.  It's been gruelling but I am now down to playing with parameters and getting sensible errors from Moodle.  At least the course arrives.  So bit by bit (or should that be byte by byte wink

Was bitten by the authentification (OAuth signature) problem seen by many in the past but found where to comment out the check as for my purposes security is not an issue.  When we do the real thing that will get sorted.

Once I get some good clean results I'll post the working php script along with pointers to each parameters origin.  Hopefully someone might come this way.

And thanks to Mary and Ken for keeping me company.  It does help just to know someone is there smile

Now just hope the efforts lead to a moodling success.

Cheers



In reply to Nigel Hoath

Re: LTi consumer simple php example

by Michael Berhorst -

Hi,

did you fixed the php script? I'm sitting before the same problem currently. :/

Greetings