added roles and student id

This commit is contained in:
Alexander Kryklia
2013-09-02 12:57:00 +03:00
parent 42bcd9c28c
commit 3e3d89e370
4 changed files with 16 additions and 2 deletions

View File

@@ -41,6 +41,8 @@ class LTIModule(LTIFields, XModule):
def get_html(self):
""" Renders parameters to template. """
# these params do not participate in oauth signing
params = {
'lti_url': self.lti_url,
'element_id': self.location.html_id(),
@@ -55,15 +57,21 @@ class LTIModule(LTIFields, XModule):
client_key=unicode(self.client_key),
client_secret=unicode(self.client_secret)
)
# @ned - why self.runtime.anonymous_student_id is None in dev env?
user_id = self.runtime.anonymous_student_id
user_id = user_id if user_id else 'default_user_id'
# must have parameters for correct signing from LTI:
body = {
'user_id': 'default_user_id',
'user_id': user_id,
'oauth_callback': 'about:blank',
'lis_outcome_service_url': '',
'lis_result_sourcedid': '',
'launch_presentation_return_url': '',
'lti_message_type': 'basic-lti-launch-request',
'lti_version': 'LTI-1p0',
'role': 'student'
}
# This is needed for body encoding:
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
@@ -80,12 +88,15 @@ class LTIModule(LTIFields, XModule):
params[u'oauth_nonce'] = params[u'OAuth oauth_nonce']
del params[u'OAuth oauth_nonce']
params['user_id'] = body['user_id']
# 0.14.2 (current) version of requests oauth library 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:
params[u'oauth_signature'] = urllib.unquote(params[u'oauth_signature']).decode('utf8')
return params