diff options
author | Ib Lundgren <ib.lundgren@gmail.com> | 2012-11-04 12:34:21 +0100 |
---|---|---|
committer | Ib Lundgren <ib.lundgren@gmail.com> | 2012-11-04 12:34:21 +0100 |
commit | 3015af5738b7ad105290e0e7ee7dc3f1ec92e51a (patch) | |
tree | 7ec172098ec1d691d471adddfbea0898a66dd82c | |
parent | b18ccffd88e4cc3113188c55a059b068dd26e2d7 (diff) | |
download | oauthlib-oauth2_provider.tar.gz |
Small unittest tweaks.oauth2_provider
-rw-r--r-- | oauthlib/oauth2/draft25/grant_types.py | 7 | ||||
-rw-r--r-- | oauthlib/oauth2/draft25/tokens.py | 4 | ||||
-rw-r--r-- | tests/oauth2/draft25/test_grant_types.py | 20 |
3 files changed, 22 insertions, 9 deletions
diff --git a/oauthlib/oauth2/draft25/grant_types.py b/oauthlib/oauth2/draft25/grant_types.py index c8d7070..9773b86 100644 --- a/oauthlib/oauth2/draft25/grant_types.py +++ b/oauthlib/oauth2/draft25/grant_types.py @@ -49,6 +49,7 @@ class RequestValidator(object): return True def validate_request_scopes(self, request): + request.state = getattr(request, u'state', None) if request.scopes: if not self.validate_scopes(request.client_id, request.scopes): raise errors.InvalidScopeError(state=request.state) @@ -107,7 +108,7 @@ class AuthorizationCodeGrant(GrantTypeBase): """Saves authorization codes for later use by the token endpoint.""" raise NotImplementedError('Subclasses must implement this method.') - def create_authorization_response(self, request): + def create_authorization_response(self, request, token_handler): try: self.request_validator.validate_request(request) @@ -425,8 +426,8 @@ class ClientCredentialsGrant(GrantTypeBase): self.request_validator.authenticate_client(request) self.validate_token_request(request) except errors.OAuth2Error as e: - return e.json - return json.dumps(token_handler(request, refresh_token=True)) + return None, {}, e.json + return None, {}, json.dumps(token_handler(request, refresh_token=True)) def validate_token_request(self, request): if not getattr(request, 'grant_type'): diff --git a/oauthlib/oauth2/draft25/tokens.py b/oauthlib/oauth2/draft25/tokens.py index a031f01..cc8c237 100644 --- a/oauthlib/oauth2/draft25/tokens.py +++ b/oauthlib/oauth2/draft25/tokens.py @@ -150,7 +150,7 @@ class BearerToken(TokenBase): def expires_in(self): return 3600 - def save_token(self, client_id, token): + def save_token(self, request, token): """Saves authorization codes for later use by the token endpoint.""" raise NotImplementedError('Subclasses must implement this method.') @@ -167,7 +167,7 @@ class BearerToken(TokenBase): if refresh_token: token[u'refresh_token'] = generate_token() - self.save_token(request.client_id, token) + self.save_token(request, token) return token def validate_request(self, request): diff --git a/tests/oauth2/draft25/test_grant_types.py b/tests/oauth2/draft25/test_grant_types.py index 935d702..419bda8 100644 --- a/tests/oauth2/draft25/test_grant_types.py +++ b/tests/oauth2/draft25/test_grant_types.py @@ -11,6 +11,7 @@ from oauthlib.oauth2.draft25.errors import UnauthorizedClientError from oauthlib.oauth2.draft25.errors import InvalidGrantError from oauthlib.oauth2.draft25.grant_types import AuthorizationCodeGrant from oauthlib.oauth2.draft25.grant_types import ImplicitGrant +from oauthlib.oauth2.draft25.grant_types import ResourceOwnerPasswordCredentialsGrant from oauthlib.oauth2.draft25.tokens import BearerToken @@ -75,6 +76,12 @@ class AuthorizationCodeGrantTest(TestCase): class ImplicitGrantTest(TestCase): + def setUp(self): + # TODO: query params + self.request = Request(u'http://a.b/path') + self.mock_validator = mock.MagicMock() + self.auth = ImplicitGrant(request_validator=self.mock_validator) + def test_create_token_response(self): # ensure json parsable containing all we want pass @@ -87,15 +94,20 @@ class ImplicitGrantTest(TestCase): class ResourceOwnerPasswordCredentialsGrantTest(TestCase): def setUp(self): - self.request = Request(u'http://a.b/path') - self.request.body = u'grant_type=password&username=john&password=doe' + self.request = Request('http://a.b/path') + self.request.grant_type = 'password' + self.request.username = 'john' + self.request.password = 'doe' + self.request.client = 'mock authenticated' + self.request.scopes = ('mocked', 'scopes') self.mock_validator = mock.MagicMock() - self.auth = ImplicitGrant(request_validator=self.mock_validator) + self.auth = ResourceOwnerPasswordCredentialsGrant( + request_validator=self.mock_validator) def test_create_token_response(self): bearer = BearerToken() bearer.save_token = mock.MagicMock() - uri, headers, body = self.auth.create_authorization_response( + uri, headers, body = self.auth.create_token_response( self.request, bearer) token = json.loads(body) self.assertIn('access_token', token) |