diff --git a/lti_consumer/lti_1p1/consumer.py b/lti_consumer/lti_1p1/consumer.py index 7341c6144cf93d036348c34f41858321ce91f2fc..5b2d16d4d0f3171e91836dd1d0539adae0362047 100644 --- a/lti_consumer/lti_1p1/consumer.py +++ b/lti_consumer/lti_1p1/consumer.py @@ -146,6 +146,9 @@ class LtiConsumer1p1: self.lti_launch_presentation_locale = None self.lti_custom_parameters = None + # Extra claims - used for custom parameter processors + self.extra_claims = {} + def set_user_data( self, user_id, @@ -241,6 +244,14 @@ class LtiConsumer1p1: self.lti_custom_parameters = custom_parameters + def set_extra_claims(self, claim): + """ + Updates launch extra claims using python's dict .update method + """ + if not isinstance(claim, dict): + raise ValueError('Invalid extra claim: {!r} is not a dict.'.format(claim)) + self.extra_claims.update(claim) + def generate_launch_request(self, resource_link_id): """ Signs LTI launch request and returns signature and OAuth parameters. @@ -288,6 +299,10 @@ class LtiConsumer1p1: if self.lti_custom_parameters: lti_parameters.update(self.lti_custom_parameters) + # Extra claims - from custom parameter processors + if self.extra_claims: + lti_parameters.update(self.extra_claims) + headers = { # This is needed for body encoding: 'Content-Type': 'application/x-www-form-urlencoded', diff --git a/lti_consumer/lti_xblock.py b/lti_consumer/lti_xblock.py index 42e1d5a83c87eaa3d68f3816db38f9acf5a5222c..6d6cd54e9009d28a408a6a2a7e6c35562a70037f 100644 --- a/lti_consumer/lti_xblock.py +++ b/lti_consumer/lti_xblock.py @@ -1009,6 +1009,16 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock): lti_consumer.set_custom_parameters(self.prefixed_custom_parameters) + for processor in self.get_parameter_processors(): + try: + default_params = getattr(processor, 'lti_xblock_default_params', {}) + lti_consumer.set_extra_claims(default_params) + lti_consumer.set_extra_claims(processor(self) or {}) + except Exception: # pylint: disable=broad-except + # Log the error without causing a 500-error. + # Useful for catching casual runtime errors in the processors. + log.exception('Error in XBlock LTI parameter processor "%s"', processor) + lti_parameters = lti_consumer.generate_launch_request(self.resource_link_id) loader = ResourceLoader(__name__) context = self._get_context_for_template() diff --git a/setup.py b/setup.py index 9a0e759c8bbbc31fbecd2b403340048af7dc9b85..6114e2d6c8f37653f109dfc4e1a5f5e1d739beb2 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ with open('README.rst') as _f: setup( name='lti-consumer-xblock', - version='3.0.2', + version='3.0.3', author='Open edX project', author_email='oscm@edx.org', description='This XBlock implements the consumer side of the LTI specification.',