def post_outcome_request(self):
        """
        POST an OAuth signed request to the Tool Consumer.
        """
        if not self.has_required_attributes():
            raise InvalidLTIConfigError(
                "OutcomeRequest does not have all required attributes"
            )

        consumer = oauth2.Consumer(key=self.consumer_key, secret=self.consumer_secret)

        client = oauth2.Client(consumer)
        # monkey_patch_headers ensures that Authorization
        # header is NOT lower cased
        monkey_patch_headers = True
        monkey_patch_function = None
        if monkey_patch_headers:
            import httplib2

            http = httplib2.Http

            normalize = http._normalize_headers

            def my_normalize(self, headers):
                # print("My Normalize", headers)
                ret = normalize(self, headers)
                if "authorization" in ret:
                    ret["Authorization"] = ret.pop("authorization")
                # print("My Normalize", ret)
                return ret

            http._normalize_headers = my_normalize
            monkey_patch_function = normalize

        response, content = client.request(
            self.lis_outcome_service_url,
            "POST",
            body=self.generate_request_xml(),
            headers={"Content-Type": "application/xml"},
        )

        if monkey_patch_headers and monkey_patch_function:
            import httplib2

            http = httplib2.Http
            http._normalize_headers = monkey_patch_function

        self.outcome_response = OutcomeResponse.from_post_response(response, content)
        return self.outcome_response
    def post_outcome_request(self):
        '''
        POST an OAuth signed request to the Tool Consumer.
        '''
        if not self.has_required_attributes():
            raise InvalidLTIConfigError(
                'OutcomeRequest does not have all required attributes')

        consumer = oauth2.Consumer(key=self.consumer_key,
                                   secret=self.consumer_secret)

        client = oauth2.Client(consumer)
        # monkey_patch_headers ensures that Authorization
        # header is NOT lower cased
        monkey_patch_headers = True
        monkey_patch_function = None
        if monkey_patch_headers:
            import httplib2
            http = httplib2.Http

            normalize = http._normalize_headers

            def my_normalize(self, headers):
                # print("My Normalize", headers)
                ret = normalize(self, headers)
                if 'authorization' in ret:
                    ret['Authorization'] = ret.pop('authorization')
                # print("My Normalize", ret)
                return ret
            http._normalize_headers = my_normalize
            monkey_patch_function = normalize

        response, content = client.request(
            self.lis_outcome_service_url,
            'POST',
            body=self.generate_request_xml(),
            headers={'Content-Type': 'application/xml'})

        if monkey_patch_headers and monkey_patch_function:
            import httplib2
            http = httplib2.Http
            http._normalize_headers = monkey_patch_function

        self.outcome_response = OutcomeResponse.from_post_response(response,
                                                                   content)
        return self.outcome_response
    def post_outcome_request(self, **kwargs):
        '''
        POST an OAuth signed request to the Tool Consumer.
        '''
        if not self.has_required_attributes():
            raise InvalidLTIConfigError(
                'OutcomeRequest does not have all required attributes')

        header_oauth = OAuth1(self.consumer_key, self.consumer_secret,
                       signature_type=SIGNATURE_TYPE_AUTH_HEADER, **kwargs)

        headers = {'Content-type': 'application/xml'}
        resp = requests.post(self.lis_outcome_service_url, auth=header_oauth,
                             data=self.generate_request_xml(),
                             headers=headers)
        outcome_resp = OutcomeResponse.from_post_response(resp, resp.content)
        self.outcome_response = outcome_resp
        return self.outcome_response
Exemple #4
0
    def post_outcome_request(self):
        '''
        POST an OAuth signed request to the Tool Consumer.
        '''
        if not self.has_required_attributes():
            raise InvalidLTIConfigError('OutcomeRequest does not have all required attributes')

        consumer = oauth2.Consumer(key = self.consumer_key,
                secret =  self.consumer_secret)

        client = oauth2.Client(consumer)

        response, content = client.request(
                self.lis_outcome_service_url,
                'POST',
                body = self.generate_request_xml(),
                headers = { 'Content-Type': 'application/xml' })

        self.outcome_response = OutcomeResponse.from_post_response(response,
                content)
        return self.outcome_response
    def post_outcome_request(self):
        '''
        POST an OAuth signed request to the Tool Consumer.
        '''
        if not self.has_required_attributes():
            raise InvalidLTIConfigError(
                'OutcomeRequest does not have all required attributes')

        consumer = oauth2.Consumer(key=self.consumer_key,
                                   secret=self.consumer_secret)

        client = oauth2.Client(consumer)

        response, content = client.request(
            self.lis_outcome_service_url,
            'POST',
            body=self.generate_request_xml(),
            headers={'Content-Type': 'application/xml'})

        self.outcome_response = OutcomeResponse.from_post_response(
            response, content)
        return self.outcome_response
    def post_outcome_request(self, **kwargs):
        '''
        POST an OAuth signed request to the Tool Consumer.
        '''
        if not self.has_required_attributes():
            raise InvalidLTIConfigError(
                'OutcomeRequest does not have all required attributes')

        header_oauth = OAuth1(self.consumer_key,
                              self.consumer_secret,
                              signature_type=SIGNATURE_TYPE_AUTH_HEADER,
                              force_include_body=True,
                              **kwargs)

        headers = {'Content-type': 'application/xml'}
        resp = requests.post(self.lis_outcome_service_url,
                             auth=header_oauth,
                             data=self.generate_request_xml(),
                             headers=headers)
        outcome_resp = OutcomeResponse.from_post_response(resp, resp.content)
        self.outcome_response = outcome_resp
        return self.outcome_response