Merge pull request #880 from edx/db/update-requests-lib
Update `requests` library to 1.2.3
This commit is contained in:
@@ -16,9 +16,9 @@ window.LTI = (function () {
|
||||
|
||||
// If the Form's action attribute is set (i.e. we can perform a normal
|
||||
// submit), then we submit the form and make the frame shown.
|
||||
if (form.attr('action')) {
|
||||
if (form.attr('action') && form.attr('action') !== 'http://www.example.com') {
|
||||
form.submit();
|
||||
element.find('.lti').addClass('rendered')
|
||||
element.find('.lti').addClass('rendered');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
"""
|
||||
Module that allows to insert LTI tools to page.
|
||||
|
||||
Module uses current edx-platform 0.14.2 version of requests (oauth part).
|
||||
Please update code when upgrading requests.
|
||||
|
||||
Protocol is oauth1, LTI version is 1.1.1:
|
||||
http://www.imsglobal.org/LTI/v1p1p1/ltiIMGv1p1p1.html
|
||||
"""
|
||||
|
||||
import logging
|
||||
import requests
|
||||
import oauthlib.oauth1
|
||||
import urllib
|
||||
|
||||
from xmodule.editing_module import MetadataOnlyEditingDescriptor
|
||||
@@ -41,9 +38,12 @@ class LTIFields(object):
|
||||
vbid=put_book_id_here
|
||||
book_location=page/put_page_number_here
|
||||
|
||||
Default non-empty url for `launch_url` is needed due to oauthlib demand (url scheme should be presented)::
|
||||
|
||||
https://github.com/idan/oauthlib/blob/master/oauthlib/oauth1/rfc5849/signature.py#L136
|
||||
"""
|
||||
lti_id = String(help="Id of the tool", default='', scope=Scope.settings)
|
||||
launch_url = String(help="URL of the tool", default='', scope=Scope.settings)
|
||||
launch_url = String(help="URL of the tool", default='http://www.example.com', scope=Scope.settings)
|
||||
custom_parameters = List(help="Custom parameters (vbid, book_location, etc..)", scope=Scope.settings)
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ class LTIModule(LTIFields, XModule):
|
||||
Also *anonymous student id* is passed to template and therefore to LTI provider.
|
||||
"""
|
||||
|
||||
client = requests.auth.Client(
|
||||
client = oauthlib.oauth1.Client(
|
||||
client_key=unicode(client_key),
|
||||
client_secret=unicode(client_secret)
|
||||
)
|
||||
@@ -215,14 +215,30 @@ class LTIModule(LTIFields, XModule):
|
||||
# appending custom parameter for signing
|
||||
body.update(custom_parameters)
|
||||
|
||||
# This is needed for body encoding:
|
||||
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
headers = {
|
||||
# This is needed for body encoding:
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
}
|
||||
|
||||
try:
|
||||
__, headers, __ = client.sign(
|
||||
unicode(self.launch_url),
|
||||
http_method=u'POST',
|
||||
body=body,
|
||||
headers=headers)
|
||||
except ValueError: # scheme not in url
|
||||
# Stubbing headers for now:
|
||||
headers = {
|
||||
u'Content-Type': u'application/x-www-form-urlencoded',
|
||||
u'Authorization': u'oAuth ' # cont..
|
||||
u'oauth_nonce="80966668944732164491378916897", ' # cont..
|
||||
u'oauth_timestamp="1378916897", ' # cont..
|
||||
u'oauth_version="1.0", ' # cont..
|
||||
u'oauth_signature_method="HMAC-SHA1", ' # cont..
|
||||
u'oauth_consumer_key="", ' # cont..
|
||||
u'oauth_signature="frVp4JuvT1mVXlxktiAUjQ7%2F1cw%3D"',
|
||||
}
|
||||
|
||||
__, headers, __ = client.sign(
|
||||
unicode(self.launch_url),
|
||||
http_method=u'POST',
|
||||
body=body,
|
||||
headers=headers)
|
||||
params = headers['Authorization']
|
||||
# parse headers to pass to template as part of context:
|
||||
params = dict([param.strip().replace('"', '').split('=') for param in params.split(',')])
|
||||
@@ -230,8 +246,8 @@ class LTIModule(LTIFields, XModule):
|
||||
params[u'oauth_nonce'] = params[u'OAuth oauth_nonce']
|
||||
del params[u'OAuth oauth_nonce']
|
||||
|
||||
# 0.14.2 (current) version of requests oauth library encodes signature,
|
||||
# with 'Content-Type': 'application/x-www-form-urlencoded'
|
||||
# oauthlib encodes signature with
|
||||
# 'Content-Type': 'application/x-www-form-urlencoded'
|
||||
# so '='' becomes '%3D'.
|
||||
# We send form via browser, so browser will encode it again,
|
||||
# So we need to decode signature back:
|
||||
|
||||
@@ -25,7 +25,7 @@ class GradingService(object):
|
||||
def __init__(self, config):
|
||||
self.username = config['username']
|
||||
self.password = config['password']
|
||||
self.session = requests.session()
|
||||
self.session = requests.Session()
|
||||
self.system = config['system']
|
||||
|
||||
def _login(self):
|
||||
@@ -42,7 +42,7 @@ class GradingService(object):
|
||||
|
||||
response.raise_for_status()
|
||||
|
||||
return response.json
|
||||
return response.json()
|
||||
|
||||
def post(self, url, data, allow_redirects=False):
|
||||
"""
|
||||
@@ -88,9 +88,10 @@ class GradingService(object):
|
||||
Returns the result of operation(). Does not catch exceptions.
|
||||
"""
|
||||
response = operation()
|
||||
if (response.json
|
||||
and response.json.get('success') is False
|
||||
and response.json.get('error') == 'login_required'):
|
||||
resp_json = response.json()
|
||||
if (resp_json
|
||||
and resp_json.get('success') is False
|
||||
and resp_json.get('error') == 'login_required'):
|
||||
# apparrently we aren't logged in. Try to fix that.
|
||||
r = self._login()
|
||||
if r and not r.get('success'):
|
||||
|
||||
@@ -62,6 +62,7 @@ def get_test_system(course_id=''):
|
||||
user=Mock(is_staff=False),
|
||||
filestore=Mock(),
|
||||
debug=True,
|
||||
hostname="edx.org",
|
||||
xqueue={'interface': None, 'callback_url': '/', 'default_queuename': 'testqueue', 'waittime': 10, 'construct_callback' : Mock(side_effect="/")},
|
||||
node_path=os.environ.get("NODE_PATH", "/usr/local/lib/node_modules"),
|
||||
xblock_field_data=lambda descriptor: descriptor._field_data,
|
||||
|
||||
@@ -833,7 +833,7 @@ class ModuleSystem(Runtime):
|
||||
def __init__(
|
||||
self, ajax_url, track_function, get_module, render_template,
|
||||
replace_urls, xblock_field_data, user=None, filestore=None,
|
||||
debug=False, xqueue=None, publish=None, node_path="",
|
||||
debug=False, hostname="", xqueue=None, publish=None, node_path="",
|
||||
anonymous_student_id='', course_id=None,
|
||||
open_ended_grading_interface=None, s3_interface=None,
|
||||
cache=None, can_execute_unsafe_code=None, replace_course_urls=None,
|
||||
@@ -897,6 +897,7 @@ class ModuleSystem(Runtime):
|
||||
self.get_module = get_module
|
||||
self.render_template = render_template
|
||||
self.DEBUG = self.debug = debug
|
||||
self.HOSTNAME = self.hostname = hostname
|
||||
self.seed = user.id if user is not None else 0
|
||||
self.replace_urls = replace_urls
|
||||
self.node_path = node_path
|
||||
|
||||
Reference in New Issue
Block a user