Handle content-type header charset value for streaming API
[twitter-api-cdsw] / oauthlib / oauth2 / rfc6749 / grant_types / base.py
1 # -*- coding: utf-8 -*-
2 """
3 oauthlib.oauth2.rfc6749.grant_types
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 """
6 from __future__ import unicode_literals, absolute_import
7
8 import logging
9
10 from oauthlib.oauth2.rfc6749 import errors, utils
11
12 log = logging.getLogger(__name__)
13
14
15 class GrantTypeBase(object):
16     error_uri = None
17     request_validator = None
18
19     def create_authorization_response(self, request, token_handler):
20         raise NotImplementedError('Subclasses must implement this method.')
21
22     def create_token_response(self, request, token_handler):
23         raise NotImplementedError('Subclasses must implement this method.')
24
25     def validate_grant_type(self, request):
26         client_id = getattr(request, 'client_id', None)
27         if not self.request_validator.validate_grant_type(client_id,
28                                                           request.grant_type, request.client, request):
29             log.debug('Unauthorized from %r (%r) access to grant type %s.',
30                       request.client_id, request.client, request.grant_type)
31             raise errors.UnauthorizedClientError(request=request)
32
33     def validate_scopes(self, request):
34         if not request.scopes:
35             request.scopes = utils.scope_to_list(request.scope) or utils.scope_to_list(
36                 self.request_validator.get_default_scopes(request.client_id, request))
37         log.debug('Validating access to scopes %r for client %r (%r).',
38                   request.scopes, request.client_id, request.client)
39         if not self.request_validator.validate_scopes(request.client_id,
40                                                       request.scopes, request.client, request):
41             raise errors.InvalidScopeError(request=request)

Benjamin Mako Hill || Want to submit a patch?