grails - Issues with sending oauth-signed lti posts to moodle -
i'm attempting send grades moodle external tool i'm developing moodle. external tool written in grails. have moodle uses oauth log users external tool. understanding, should able change user's grade sending post request signed oauth url given me on login, xml document containing lis_result_sourcedid parameter given on login grade. code sending post request working save part signing request -- moodle consistently giving me response saying "message signature not valid".
here code sending post request:
string rawxml = getrawxml(); curmessageid++; def jsonmap = json.parsejson(sourcedid) rawxml = rawxml.replace("{message_id}", long.tostring(curmessageid)) .replace("{score}", double.tostring(grade)) .replace("{text_data}", textdata) .replace("{sourced_id}", sourcedid) def request = new httprequest() .seturi(responseurl) .setcontenttype("text/xml") .setaccept("text/xml") def factory = new referencehttpclientfactory() def client = factory.createhttpclient() def map = [:] map['oauth_callback'] = "about:blank" map['oauth_signature_method'] = 'hmac-sha1' map['oauth_timestamp'] = long.tostring(system.currenttimemillis()) //map['oauth_token'] = "my-secret" map['oauth_consumer_key'] = "my-secret" map['oauth_version'] = '1.0' map['oauth_nonce'] = generatenonce() def headermap = [:] def oauthsig = ltiservice.generateoauthsignature("post", responseurl, "my-secret", map) println(oauthsig) map['oauth_signature'] = oauthsig string authheader = "auth " def keys = [] map.each{ k, v -> keys.add(k)} keys = keys.sort(); keys.each {k -> authheader = authheader + k + '="' + ltiservice.encode(map.getat(k)) + '", '} authheader = authheader.substring(0,authheader.length() - 1) println(authheader) request.setheader("authorization", authheader) def response = client.post(request, rawxml) println(response.status) println(response.getentity(string))
here xml document using template:
<?xml version = '1.0' encoding = 'utf-8'?> <imsx_poxenveloperequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0"> <imsx_poxheader> <imsx_poxrequestheaderinfo> <imsx_version>v1.0</imsx_version> <imsx_messageidentifier>{message_id}</imsx_messageidentifier> </imsx_poxrequestheaderinfo> </imsx_poxheader> <imsx_poxbody> <replaceresultrequest> <resultrecord> <sourcedguid> <sourcedid>{sourced_id}</sourcedid> </sourcedguid> <result> <resultscore> <language>en</language> <textstring>{score}</textstring> </resultscore> <!-- added element --> <resultdata> <text>{text_data}</text> </resultdata> </result> </resultrecord> </replaceresultrequest> </imsx_poxbody> </imsx_poxenveloperequest>
and here response i'm getting:
<imsx_poxenveloperesponse xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0"> <imsx_poxheader> <imsx_poxresponseheaderinfo> <imsx_version>v1.0</imsx_version> <imsx_messageidentifier>1066317126</imsx_messageidentifier> <imsx_statusinfo> <imsx_codemajor>failure</imsx_codemajor> <imsx_severity>status</imsx_severity> <imsx_description>message signature not valid</imsx_description> <imsx_messagerefidentifier/> <imsx_operationrefidentifier>unknownrequest </imsx_operationrefidentifier> </imsx_statusinfo> </imsx_poxresponseheaderinfo> </imsx_poxheader> <imsx_poxbody> <unknownresponse/> </imsx_poxbody> </imsx_poxenveloperesponse>
Comments
Post a Comment