LTI Demo for canvas (Java))

foreword

The easiest way to develop or add new functionality to canvas is to develop an LTI. The following is a Demo developed for canvas that can modify the sis id at will.

introduce

LTI is a standard for connecting LMS with External Tool. It uses OAuth for signature authentication to complete user authentication between two Webs.

Workflow

Preparation: Configure the LTI startup link in the LMS,

1. LMS signs the next POST request according to the configured key and secret

2. After LTI receives the request, it certifies the signature.

3. After successful authentication in step 2, perform the corresponding registration and login steps according to the different web services connected (this step should be performed automatically by the system, and should not be guided by the user).

4. After completing the login process, go to the connected web application. Data can be sent back to canvas throughout the use of other web applications.

5. Exit the web application and return to canvas. According to the corresponding return_uri, return to the corresponding canvas page.

develop

If there is an LTI certified library, it will save a lot of trouble.

Ruby uses the ims-lti gem. And Java is as follows:

<dependency>
    <groupId>org.imsglobal</groupId>
    <artifactId>basiclti-util</artifactId>
    <version>1.2.0</version>
</dependency>

LTI certification category:

public  interface LTIAuthI { // Different login methods after successful authentication 
    void login(HttpServletRequest request, HttpServletResponse response);

    default void auth(HttpServletRequest request, HttpServletResponse response) {
        LtiVerifier ltiVerifier = new LtiOauthVerifier();
        String key = request.getParameter("oauth_consumer_key");
        try {
            LtiVerificationResult ltiResult = ltiVerifier.verify(request, LTIAuthKeys.getSecret(key));
            if(ltiResult.getSuccess()) {
                //认证成功
                login(request, response);
            }
        } catch (LtiVerificationException e) {
            e.printStackTrace ();
        }
    }
}

Possible login methods:

    public void login(HttpServletRequest request, HttpServletResponse response) {
        request.getSession().setAttribute("return_url", request.getParameter("launch_presentation_return_url"));
        request.getSession().setAttribute("user_id",userService.getUserId(request.getParameter("user_id")));
    }

After successful login, jump to a link of an existing web application or jump to a link of LTI. LTI can also be viewed as a web application:

@RequestMapping(value="/")
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws IOException {
        if(request.getSession().getAttribute("user_id") == null) {
            response.sendError(403, "Forbidden");
            return null;
        }else {
            Long userId = (Long)request.getSession().getAttribute("user_id");
            return new ModelAndView("studentinfo", "sisId", pseudonymsService.getSisIdByUserId(userId));
        }
}

Summarize:

1. LTI is equivalent to a web program that can only log in through the POST request of the LMS.

2. The Java version of basicclti-util needs to use the latest version, which is currently 1.2.0. The version of the wiki content on github is still 1.1.2.

3. Attach the example canvasLTI configuration xml:

<?xml version="1.0" encoding="UTF-8"?>
<cartridge_basiclti_link xmlns="http://www.imsglobal.org/xsd/imslticc_v1p0"
                         xmlns:blti = "http://www.imsglobal.org/xsd/imsbasiclti_v1p0"
                         xmlns:lticm ="http://www.imsglobal.org/xsd/imslticm_v1p0"
                         xmlns:lticp ="http://www.imsglobal.org/xsd/imslticp_v1p0"
                         xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation = "http://www.imsglobal.org/xsd/imslticc_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0.xsd
    http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
    http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
    http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
    <blti:launch_url>http://127.0.0.1/canvas_lti/studentinfo/launch</blti:launch_url>
    <blti:title>SetStudentInfo</blti:title>
    <blti:description>Add student info to canvas</blti:description>
    <blti:extensions platform="canvas.instructure.com">
        <lticm:property name="privacy_level">public</lticm:property>
        <lticm:options name="user_navigation">
            <lticm:options name="labels">
                <lticm:property name="en">SetStudentInfo</lticm:property>
                <lticm:property name="zh">配置学籍信息</lticm:property>
            </lticm:options>
            <lticm:property name="enabled">true</lticm:property>
        </lticm:options>
    </blti:extensions>
</cartridge_basiclti_link>

 

4. Attach the canvas post request and submit the parameters:

tool_consumer_info_product_family_code : canvas
resource_link_title : 测试
context_title : canvas使用学习
ext_outcomes_tool_placement_url : http://127.0.0.1:4567/api/lti/v1/turnitin/outcomes_placement/1
roles : urn:lti:instrole:ims/lis/Administrator
tool_consumer_instance_name : test
ext_lti_assignment_id : f4e5f0c9-11f0-408d-b1d6-3ec9e858ce4e
tool_consumer_instance_guid : b7ba4e5ca3e16754b4465d4949721cfabf92b2c1.127.0.0.1
custom_canvas_assignment_title : 测试
resource_link_id : 8edac495567b06c1756f5dc6be98a119dc575749
oauth_signature_method : HMAC-SHA1
oauth_version : 1.0
launch_presentation_return_url : http://127.0.0.1:4567/courses/1/assignments
ext_outcome_data_values_accepted : url,text
ext_ims_lis_basic_outcome_url : http://127.0.0.1:4567/api/lti/v1/tools/1/ext_grade_passback
custom_canvas_enrollment_state :
lti_version : LTI-1p0
oauth_signature : wVkTM2lkBF9Fk6EdZAqbSNtAm4c=
ext_roles : urn:lti:instrole:ims/lis/Administrator,urn:lti:sysrole:ims/lis/SysAdmin,urn:lti:sysrole:ims/lis/User
oauth_consumer_key : ojqd
launch_presentation_locale : zh-Hans
oauth_timestamp : 1523941687
tool_consumer_instance_contact_email : [email protected]
lis_outcome_service_url : http://127.0.0.1:4567/api/lti/v1/tools/1/grade_passback
ext_outcome_result_total_score_accepted : true
oauth_nonce : 17LRyLaG7ud3CFBiC9M3ZuSdXzNkO9T5qcDnuopUVI
custom_canvas_assignment_points_possible : 0
lti_message_type : basic-lti-launch-request
oauth_callback : about:blank
user_id : 29ffb607a1eab7755f771ba442df023dc42b9042
tool_consumer_info_version : cloud
context_id : abff60ace038d671c7300fea7212bbff16fb1fef
context_label : canvas
launch_presentation_document_target : iframe

postscript:

I am also a novice, record the first Demo. Welcome criticism and correction: [email protected]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324610351&siteId=291194637