Esempio n. 1
0
 def _assert_success(self, data, expected_scopes):
     form = AccessTokenExchangeForm(request=self.request, data=data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data["user"], self.user)
     self.assertEqual(form.cleaned_data["client"], self.oauth_client)
     self.assertEqual(scope.to_names(form.cleaned_data["scope"]),
                      expected_scopes)
Esempio n. 2
0
    def post(self, request, _backend):  # pylint: disable=arguments-differ
        """
        Handle POST requests to get a first-party access token.
        """
        form = AccessTokenExchangeForm(request=request, oauth2_adapter=self.oauth2_adapter, data=request.POST)  # pylint: disable=no-member
        if not form.is_valid():
            return self.error_response(form.errors)

        user = form.cleaned_data["user"]
        scope = form.cleaned_data["scope"]
        client = form.cleaned_data["client"]

        return self.exchange_access_token(request, user, scope, client)
Esempio n. 3
0
    def post(self, request, _backend):  # pylint: disable=arguments-differ
        form = AccessTokenExchangeForm(request=request, data=request.POST)
        if not form.is_valid():
            return self.error_response(form.errors)

        user = form.cleaned_data["user"]
        scope = form.cleaned_data["scope"]
        client = form.cleaned_data["client"]

        if constants.SINGLE_ACCESS_TOKEN:
            edx_access_token = self.get_access_token(request, user, scope, client)
        else:
            edx_access_token = self.create_access_token(request, user, scope, client)

        return self.access_token_response(edx_access_token)
Esempio n. 4
0
    def post(self, request, _backend):  # pylint: disable=arguments-differ
        """
        Handle POST requests to get a first-party access token.
        """
        form = AccessTokenExchangeForm(request=request,
                                       oauth2_adapter=self.oauth2_adapter,
                                       data=request.POST)  # pylint: disable=no-member
        if not form.is_valid():
            return self.error_response(form.errors)

        user = form.cleaned_data["user"]
        scope = form.cleaned_data["scope"]
        client = form.cleaned_data["client"]

        return self.exchange_access_token(request, user, scope, client)
Esempio n. 5
0
 def _assert_error(self, data, expected_error, expected_error_description):
     form = AccessTokenExchangeForm(request=self.request, data=data)
     self.assertEqual(
         form.errors,
         {"error": expected_error, "error_description": expected_error_description}
     )
     self.assertNotIn("partial_pipeline", self.request.session)
Esempio n. 6
0
    def post(self, request, _backend):  # pylint: disable=arguments-differ
        form = AccessTokenExchangeForm(request=request, data=request.POST)
        if not form.is_valid():
            return self.error_response(form.errors)

        user = form.cleaned_data["user"]
        scope = form.cleaned_data["scope"]
        client = form.cleaned_data["client"]

        if constants.SINGLE_ACCESS_TOKEN:
            edx_access_token = self.get_access_token(request, user, scope,
                                                     client)
        else:
            edx_access_token = self.create_access_token(
                request, user, scope, client)

        return self.access_token_response(edx_access_token)
Esempio n. 7
0
 def _assert_success(self, data, expected_scopes):
     form = AccessTokenExchangeForm(request=self.request, data=data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data["user"], self.user)
     self.assertEqual(form.cleaned_data["client"], self.oauth_client)
     self.assertEqual(scope.to_names(form.cleaned_data["scope"]), expected_scopes)