]> projects.mako.cc - twitter-api-cdsw/blob - oauthlib/oauth2/rfc6749/grant_types/base.py
4a8017fa30aa2de5033cd3f27b49f475bbfad727
[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         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)
31
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)

Benjamin Mako Hill || Want to submit a patch?