Commit e79740de by John Lee

Sign the requests going from the XBlock to the SY server

parent 5a0380b5
"""The base class for School Yourself XBlocks (lessons and reviews).""" """The base class for School Yourself XBlocks (lessons and reviews)."""
import hmac
import os import os
import pkg_resources import pkg_resources
...@@ -103,16 +104,22 @@ class SchoolYourselfXBlock(XBlock): ...@@ -103,16 +104,22 @@ class SchoolYourselfXBlock(XBlock):
return template.render_unicode(**context) return template.render_unicode(**context)
def get_partner_url_params(self): def get_partner_url_params(self, shared_key=None):
"""A helper method that generates a dict of URL params that we can """A helper method that generates a dict of URL params that we can
append to the end of a URL, containing the partner ID and the append to the end of a URL, containing the partner ID and the
user's anonymouse user ID. These are typically transmitted as URL user's anonymouse user ID. These are typically transmitted as URL
params. in the iframes.""" params. in the iframes.
url_params = {"id": self.module_id,
"partner": "edx"} If a shared_key is provided and there is a username to encode,
we will sign it with the shared key.
"""
url_params = {"partner": "edx"}
user_id = self.get_student_id() user_id = self.get_student_id()
if user_id: if user_id:
url_params["partner_user_id"] = user_id url_params["partner_user_id"] = user_id
if shared_key:
url_params["partner_signature"] = hmac.new(str(shared_key),
user_id).hexdigest()
return url_params return url_params
......
...@@ -24,7 +24,8 @@ class SchoolYourselfLessonXBlock(SchoolYourselfXBlock): ...@@ -24,7 +24,8 @@ class SchoolYourselfLessonXBlock(SchoolYourselfXBlock):
""" """
# Construct the URL we're going to stuff into the iframe once # Construct the URL we're going to stuff into the iframe once
# it gets launched: # it gets launched:
url_params = self.get_partner_url_params() url_params = self.get_partner_url_params(self.shared_key)
url_params["id"] = self.module_id
# Set up the screenshot URL: # Set up the screenshot URL:
screenshot_url = "%s/page/screenshot/%s" % (self.base_url, screenshot_url = "%s/page/screenshot/%s" % (self.base_url,
......
...@@ -28,7 +28,8 @@ class SchoolYourselfReviewXBlock(SchoolYourselfXBlock): ...@@ -28,7 +28,8 @@ class SchoolYourselfReviewXBlock(SchoolYourselfXBlock):
""" """
# Construct the URL we're going to stuff into the iframe once # Construct the URL we're going to stuff into the iframe once
# it gets launched: # it gets launched:
url_params = self.get_partner_url_params() url_params = self.get_partner_url_params(self.shared_key)
url_params["module"] = self.module_id
# Set up the screenshot URL: # Set up the screenshot URL:
screenshot_url = "%s/page/screenshot/%s" % (self.base_url, screenshot_url = "%s/page/screenshot/%s" % (self.base_url,
...@@ -73,7 +74,8 @@ class SchoolYourselfReviewXBlock(SchoolYourselfXBlock): ...@@ -73,7 +74,8 @@ class SchoolYourselfReviewXBlock(SchoolYourselfXBlock):
"""\ """\
<vertical_demo> <vertical_demo>
<schoolyourself_review <schoolyourself_review
module_id="geometry/lines_rays" module_id="algebra/multiplication"
shared_key="test"
/> />
</vertical_demo> </vertical_demo>
"""), """),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment