1 # -*- coding: utf-8 -*-
3 oauthlib.oauth2.rfc6749.grant_types
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 from __future__ import unicode_literals, absolute_import
10 from oauthlib.oauth2.rfc6749 import errors, utils
12 log = logging.getLogger(__name__)
15 class GrantTypeBase(object):
17 request_validator = None
19 def create_authorization_response(self, request, token_handler):
20 raise NotImplementedError('Subclasses must implement this method.')
22 def create_token_response(self, request, token_handler):
23 raise NotImplementedError('Subclasses must implement this method.')
25 def validate_grant_type(self, request):
26 if not self.request_validator.validate_grant_type(request.client_id,
27 request.grant_type, request.client, request):
28 log.debug('Unauthorized from %r (%r) access to grant type %s.',
29 request.client_id, request.client, request.grant_type)
30 raise errors.UnauthorizedClientError(request=request)
32 def validate_scopes(self, request):
33 if not request.scopes:
34 request.scopes = utils.scope_to_list(request.scope) or utils.scope_to_list(
35 self.request_validator.get_default_scopes(request.client_id, request))
36 log.debug('Validating access to scopes %r for client %r (%r).',
37 request.scopes, request.client_id, request.client)
38 if not self.request_validator.validate_scopes(request.client_id,
39 request.scopes, request.client, request):
40 raise errors.InvalidScopeError(request=request)