Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #22 from ckelly/develop

Fix issue when requesting token with grant_type client_credentials
  • Loading branch information...
commit 04381b0f9e444a6b7d2deb6993cc96939e33586f 2 parents 8a84ded + 694827b
Brent Hagany bhagany authored
6 oauth2app/token.py
View
@@ -409,6 +409,6 @@ def _get_client_credentials_token(self):
if self.authentication_method == MAC:
access_token.mac_key = KeyGenerator(MAC_KEY_LENGTH)()
access_ranges = AccessRange.objects.filter(key__in=self.scope) if self.scope else []
- self.access_token.scope = access_ranges
- self.access_token.save()
- return self.access_token
+ access_token.scope = access_ranges
+ access_token.save()
+ return access_token
1  tests/testsite/apps/api/tests/__init__.py
View
@@ -5,4 +5,5 @@
from .mac import MACTestCase
from .bearer import BearerTestCase
from .responsetype import ResponseTypeTestCase
+from .granttype import GrantTypeTestCase
from .config import ConfigTestCase
59 tests/testsite/apps/api/tests/granttype.py
View
@@ -0,0 +1,59 @@
+#-*- coding: utf-8 -*-
+
+from simplejson import loads
+from base64 import b64encode
+from django.utils import unittest
+from django.contrib.auth.models import User
+from oauth2app.models import Client
+from django.test.client import Client as DjangoTestClient
+
+
+USER_USERNAME = "testuser"
+USER_PASSWORD = "testpassword"
+USER_EMAIL = "user@example.com"
+USER_FIRSTNAME = "Foo"
+USER_LASTNAME = "Bar"
+CLIENT_USERNAME = "client"
+CLIENT_EMAIL = "client@example.com"
+REDIRECT_URI = "http://example.com/callback"
+
+
+class GrantTypeTestCase(unittest.TestCase):
+
+ user = None
+ client_holder = None
+ client_application = None
+
+ def setUp(self):
+ self.user = User.objects.create_user(
+ USER_USERNAME,
+ USER_EMAIL,
+ USER_PASSWORD)
+ self.user.first_name = USER_FIRSTNAME
+ self.user.last_name = USER_LASTNAME
+ self.user.save()
+ self.client = User.objects.create_user(CLIENT_USERNAME, CLIENT_EMAIL)
+ self.client_application = Client.objects.create(
+ name="TestApplication",
+ user=self.client)
+
+ def tearDown(self):
+ self.user.delete()
+ self.client.delete()
+ self.client_application.delete()
+
+ def test_00_grant_type_client_credentials(self):
+ user = DjangoTestClient()
+ user.login(username=USER_USERNAME, password=USER_PASSWORD)
+ client = DjangoTestClient()
+ parameters = {
+ "client_id": self.client_application.key,
+ "grant_type": "client_credentials",
+ "redirect_uri": REDIRECT_URI}
+ basic_auth = b64encode("%s:%s" % (self.client_application.key,
+ self.client_application.secret))
+ response = client.get(
+ "/oauth2/token",
+ parameters,
+ HTTP_AUTHORIZATION="Basic %s" % basic_auth)
+ token = loads(response.content)
Please sign in to comment.
Something went wrong with that request. Please try again.