def log_in_with_lti(self, user=None, password=None, lti_params=None): """Log a user in with fake LTI data.""" if user is None: user = self.user if lti_params is None: lti_params = self.LTI_PARAMS.copy() lti_params['lis_person_sourcedid'] = user.username lti_params['lis_person_contact_email_primary'] = user.email lti_params['custom_assignment_id'] = unicode(self.assignment.pk) lti_params['custom_question_id'] = unicode(self.question.pk) LtiUserData.store_lti_parameters(user, LTIView.authentication_manager, lti_params) self.client.login(username=user.username, password=password or 'test')
def log_in_with_lti(self, user=None, password=None, lti_params=None): """Log a user in with fake LTI data.""" if user is None: user = self.user if lti_params is None: lti_params = self.LTI_PARAMS.copy() lti_params['lis_person_sourcedid'] = user.username lti_params['lis_person_contact_email_primary'] = user.email lti_params['custom_assignment_id'] = unicode(self.assignment.pk) lti_params['custom_question_id'] = unicode(self.question.pk) LtiUserData.store_lti_parameters(user, LTIView.authentication_manager, lti_params) self.client.login(username=user.username, password=password or 'test')
2. This is OpenID redirect from edx if actual LTI request was send anonymously - already validated LTI parameters and stored them in session - take them from session When lti parameters are ready (either taken from session or parsed and validated from request) store them in DB for later """ if cls.SESSION_KEY in request.session and not cls._is_new_lti_request( request): lti_parameters = request.session[cls.SESSION_KEY] del request.session[cls.SESSION_KEY] else: try: lti_parameters = cls._get_lti_parameters_from_request(request) except oauth2.Error, e: _logger.exception(u"Invalid LTI Request") return HttpResponseBadRequest(u"Invalid LTI Request: " + e.message) lti_data = LtiUserData.store_lti_parameters( request.user, cls.authentication_manager, cls.lti_param_filter(lti_parameters)) Signals.LTI.received.send(cls, user=request.user, lti_data=lti_data) return HttpResponseRedirect( cls.authentication_manager.authenticated_redirect_to( request, lti_parameters)) @classmethod def _is_new_lti_request(cls, request): return 'lis_result_sourcedid' in request.POST
def process_authenticated_lti(cls, request): """ There are two options: 1. This is actual LTI request made with cookies already set - need parsing and validating LTI parameters 2. This is OpenID redirect from edx if actual LTI request was send anonymously - already validated LTI parameters and stored them in session - take them from session When lti parameters are ready (either taken from session or parsed and validated from request) store them in DB for later """ if cls.SESSION_KEY in request.session and not cls._is_new_lti_request(request): lti_parameters = request.session[cls.SESSION_KEY] del request.session[cls.SESSION_KEY] else: try: lti_parameters = cls._get_lti_parameters_from_request(request) except oauth2.Error, e: _logger.exception(u"Invalid LTI Request") return HttpResponseBadRequest(u"Invalid LTI Request: " + e.message) lti_data = LtiUserData.store_lti_parameters( request.user, cls.authentication_manager, cls.lti_param_filter(lti_parameters) ) Signals.LTI.received.send(cls, user=request.user, lti_data=lti_data) return HttpResponseRedirect(cls.authentication_manager.authenticated_redirect_to(request, lti_parameters)) @classmethod def _is_new_lti_request(cls, request): return 'lis_result_sourcedid' in request.POST