xcesaralejandro / lti1p3
此包为laravel提供了一个简单的lti 1.3集成
Requires
- php: ^8.0
- firebase/php-jwt: ^6.10
- guzzlehttp/guzzle: ^7.0.1
- ramsey/uuid: ^4.1
Requires (Dev)
- orchestra/testbench: ^6.16
README
用法
1.- 将包添加到项目中
composer require xcesaralejandro/lti1p3
2.- 发布提供者
php artisan vendor:publish --provider="xcesaralejandro\lti1p3\Providers\Lti1p3ServiceProvider" --force
3.- 在您的 .ENV 中添加管理员凭证
LTI1P3_ADMIN_USERNAME=example@lti1p3.cl
LTI1P3_ADMIN_PASSWORD=lti1p3_admin
4.- 运行迁移
php artisan migrate
5.- 完成配置文件
在发布我们的提供者之后,我们将在config文件夹中找到一个名为lti1p3.php的文件,在那里我们将完成配置。以下是我将留下的必需密钥,其余的应该是默认值,除非你理解你正在更改。
VERIFY_HTTPS_CERTIFICATE
如果为true,将不允许自签名https证书。
KID
由你发明的一个标识符,这将被用于在Json Web Tokens (JWT)中标识公钥
PRIVATE_KEY
一个私有的RSA密钥
你可以在以下位置生成一个新的2048位RSA私钥:https://travistidwell.com/jsencrypt/demo/
注意
如果你在使用一些可逆代理,那么提供者发布的包样式可能会尝试使用http而不是https进行加载,这会产生错误。要修复这个问题,你可以在AppServiceProvider中强制使用https方案,在boot方法中添加\URL::forceScheme('https');
。
重要
我建议你配置一个本地域名进行开发,因为当使用JWT时,默认域名(localhost)、127.0.0.1或你的当前IP可能不适用于签名。
开始开发
应用程序将发布模型和控制台,你可以从那里开始开发。
一旦注册了一个平台(LMS),该包将负责同步和更新来自LMS的所有数据,或者如果不存在,则创建它。我们指的数据包括平台、课程、资源、用户等信息。
一旦启动结束,LtiController将在不同的方法中被调用,具体取决于流程的最终状态。
<?php
namespace App\Http\Controllers;
use xcesaralejandro\lti1p3\Http\Controllers\Lti1p3Controller;
class LtiController extends Lti1p3Controller {
/*
Important!
Consider that an LTI can be added on multiple sides,
sometimes your LTI can receive LtiResourceLinkRequest and LtiDeepLinkingRequest triggers
*/
public function onResourceLinkRequest(string $instance_id) : mixed {
return parent::onResourceLinkRequest($instance_id);
// Do something, here it is not necessary to call the parent function,
// it is only to maintain the example functionality
// This method is called when the lti launch is of type LtiResourceLinkRequest
// You can read about it here: http://www.imsglobal.org/spec/lti/v1p3/#resource-link-launch-request-message
// In human words, it is the launch of the LTI after doing the validations behind the scenes and the synchronization
// of the data that arrives from the LMS with the local platform (The one that you must now start developing).
// Sometimes this launch can be skipped by a custom redirect if you defined it in the LMS or it is a LtiDeepLinkingRequest.
}
public function onDeepLinkingRequest(string $instance_id) : mixed {
return parent::onDeepLinkingRequest($instance_id);
// Do something, here it is not necessary to call the parent function,
// it is only to maintain the example functionality
// This method is called when the lti launch is of type LtiDeepLinkingRequest
// You can read about it here: https://www.imsglobal.org/spec/lti-dl/v2p0#overview
// In human words, it is the launch of the LTI when it comes to DeepLinking. This, depending on the location where you add your LTI,
// allows you to generate custom resources, return tasks, among other things.
// I recommend reading the specification because to date I haven't tested everything it allows (UPS!).
// In such a launch you must reply back to the LMS with a DeepLinking message to end the cycle.
// You can browse the original model to review how the example works.
}
public function onError(mixed $exception = null) : mixed {
return parent::onError($exception);
// Do something, here it is not necessary to call the parent function,
// it is only to maintain the example functionality
// The onError method will be thrown when an invalid connection is attempted,
// something goes wrong in the launch process (LMS-LTI). If it is the latter case,
// it is most likely due to some problem with the configuration.
// If you're sure you've set everything up correctly and you're still getting errors,
// open a github bug, I'll be happy to cry with you for not understanding what's wrong.
}
}
对于注册平台
在工具面板中登录
https://YOUR_APP_LARAVEL_DOMAIN/lti1p3/login
(访问凭证是你在 .ENV 中配置的(第3点))
工具JWKS端点
https://YOUR_APP_LARAVEL_DOMAIN/api/lti1p3/jwks
工具连接
在相应平台上的所有必需的url(除了jwks)是
https://YOUR_APP_LARAVEL_DOMAIN/lti1p3/connect