Пример #1
0
    def get_context_data(self, **kwargs):
        role = self.request.GET.get('role', '')
        campus = self.request.GET.get('campus', '')

        lti_parameters = [
            ("roles", self._lti_role[role]),
            ("ext_roles", self._lti_ext_role[role]),
            ("custom_canvas_account_sis_id",
             'uwcourse:{}:arts-&-sciences:psych:psych'.format(campus)),
            ("oauth_timestamp", generate_timestamp()),
            ("oauth_nonce", generate_nonce()),
            ("resource_link_title",
             "UW LTI Development ({})".format(self.lti_app())),
        ]

        lti_parameters += self._static_lti_parameters

        # sign payload
        lti_app_uri = self.lti_app_uri()
        sbs = signature_base_string('POST', base_string_uri(lti_app_uri + '/'),
                                    normalize_parameters(lti_parameters))
        client_key = self._client_key
        client = Client(client_key,
                        client_secret=self._client_secrets[client_key])
        signature = sign_hmac_sha1_with_client(sbs, client)
        lti_parameters.append(("oauth_signature", signature))

        context = super().get_context_data(**kwargs)
        context['uri'] = lti_app_uri
        context['campus'] = campus
        context['role_name'] = role
        context['lti_parameters'] = lti_parameters
        return context
Пример #2
0
    def test_sign_hmac_sha1_with_client(self):
        self.assertRaises(ValueError, sign_hmac_sha1_with_client,
                          self.control_base_string, self.client)

        self.client.decode()
        sign = sign_hmac_sha1_with_client(self.control_base_string,
                                          self.client)

        self.assertEqual(len(sign), 28)
        self.assertEqual(sign, self.control_signature)
Пример #3
0
    def test_sign_hmac_sha1_with_client(self):
        self.assertRaises(ValueError,
            sign_hmac_sha1_with_client,
            self.control_base_string,
            self.client)

        self.client.decode()
        sign = sign_hmac_sha1_with_client(
            self.control_base_string, self.client)

        self.assertEqual(len(sign), 28)
        self.assertEqual(sign, self.control_signature)
Пример #4
0
 def test_sign_hmac_sha1_with_client(self):
     """
     Test sign and verify with HMAC-SHA1.
     """
     self.assertEqual(
         self.expected_signature_hmac_sha1,
         sign_hmac_sha1_with_client(self.eg_signature_base_string,
                                    self.hmac_client))
     self.assertTrue(verify_hmac_sha1(
         MockRequest('POST',
                     'http://example.com/request',
                     self.eg_params,
                     self.expected_signature_hmac_sha1),
         self.hmac_client.client_secret,
         self.hmac_client.resource_owner_secret))