用于包装凯尔特人服务的python库

celtic_lib的Python项目详细描述


这个模块包含凯尔特人服务的一个薄包装 允许跨平台LTI验证。

依赖关系

测试

tox用作此库的测试运行程序。它被配置为 对PY27、PY35和PY36运行测试。

pip install tox
tox

用法

from celtic_lib import get_lti_validator, LTIValidatorException

LTI_LISTEN_LOCATION = "https://localhost:8000/lti"

def handle_request(request):
    """
        request contains some LTI payload you just received in your application
    """

    app_key = "some_long_unique_string_unique_to_this_application"
    celtic_service_uri = "https://location_of_celtic_service.net/"

    lti_validator = get_lti_validator(celtic_service_uri, app_key)

    http_method = request.method # Will be "POST", since we are only listening on the POST endpoint
    try:
        status, result = lti_validator.validate_request(LTI_LISTEN_LOCATION, http_method, request.POST)
        return print("Request is valid and can be trusted")
    except LTIValidatorException as e:
        return print("Request failed:", e.message, "|", e.status_code)

# router is an imaginary application router.
#   For purposes of this is makes the handle_lti_request function handle all POST requests which are directed at LTI_LISTEN_LOCATION
router.on(LTI_LISTEN_LOCATION, "POST", handle_lti_request)

架构

这个模块相当简单,它将任何LTI请求转发给 包含^{tt2}记录的安全端点$ 以及secret_key。然后,此远程终结点验证请求, 并返回指示其有效性的简单响应。

DataRequester此类公开一个post方法,该方法接受 凯尔特人服务端点,以及发送它的post数据。它返回 凯尔特人的回应包装在以下界面中:

* status_code<int>
* json()<dict>

这个类的主要原因是允许用户交换 为他们自己提供默认的DataRequester,以便更好地控制 应用程序

LTIValidator处理LTI管道的类 验证。它被赋予一个凯尔特服务uri、一个app_key和一个 DataRequester实例。用户只需调用 validate_request方法,具有要确定的转发LTI负载 它的有效性。

LTIValidatorException当服务器返回 关于LTI响应的错误代码不正确。异常暴露了 以下数据:

* message<string> - The error message the CELTIC server responded with
* status_code<int> - The HTTP status code the CELTIC server responded with
* errors<dict> - The response body the CELTIC service responded with

开发

要对此软件包进行改进,需要执行以下操作:

* A python environment
* [pandoc](https://pandoc.org/installing.html) is used to convert this README.md into `reStructuredText`
    1. First: pip install pypandoc
    2. Second: Download installer from pandoc website

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从其BlobKey获取Google云存储文件   java*Vert。x*:如何在同步代码中处理   java HikaiCP:如何查看连接池大小?   java解析依赖项的重复版本   java如何删除TableColumn中的HTML标记   Maven依赖项找不到sendgridjava的zip文件   Java可用的垃圾收集算法   java IntelliJ git集成技巧和技巧   java如何在安卓中实现应用内支付?   java如何在安卓中从whatsapp获取pdf文件数据到我的应用程序?   有没有一种方法可以使用JavaScript(Vue.js)将Java应用程序(游戏)实现到网站中   使用SWT浏览器进行java-to-javascript通信的问题   java在Android手机上更改字体大小后启用textView内的滚动条