|
11 | 11 | from oauthlib.oauth2 import RequestValidator
|
12 | 12 |
|
13 | 13 | from .compat import unquote_plus
|
14 |
| -from .models import Grant, AccessToken, RefreshToken, get_application_model |
| 14 | +from .models import Grant, AccessToken, RefreshToken, get_application_model, AbstractApplication |
15 | 15 | from .settings import oauth2_settings
|
16 | 16 |
|
17 |
| -Application = get_application_model() |
18 |
| - |
19 | 17 | log = logging.getLogger('oauth2_provider')
|
20 | 18 |
|
21 | 19 | GRANT_TYPE_MAPPING = {
|
22 |
| - 'authorization_code': (Application.GRANT_AUTHORIZATION_CODE,), |
23 |
| - 'password': (Application.GRANT_PASSWORD,), |
24 |
| - 'client_credentials': (Application.GRANT_CLIENT_CREDENTIALS,), |
25 |
| - 'refresh_token': (Application.GRANT_AUTHORIZATION_CODE, Application.GRANT_PASSWORD, |
26 |
| - Application.GRANT_CLIENT_CREDENTIALS) |
| 20 | + 'authorization_code': (AbstractApplication.GRANT_AUTHORIZATION_CODE,), |
| 21 | + 'password': (AbstractApplication.GRANT_PASSWORD,), |
| 22 | + 'client_credentials': (AbstractApplication.GRANT_CLIENT_CREDENTIALS,), |
| 23 | + 'refresh_token': (AbstractApplication.GRANT_AUTHORIZATION_CODE, AbstractApplication.GRANT_PASSWORD, |
| 24 | + AbstractApplication.GRANT_CLIENT_CREDENTIALS) |
27 | 25 | }
|
28 | 26 |
|
29 | 27 |
|
@@ -117,6 +115,7 @@ def _load_application(self, client_id, request):
|
117 | 115 | # we want to be sure that request has the client attribute!
|
118 | 116 | assert hasattr(request, "client"), "'request' instance has no 'client' attribute"
|
119 | 117 |
|
| 118 | + Application = get_application_model() |
120 | 119 | try:
|
121 | 120 | request.client = request.client or Application.objects.get(client_id=client_id)
|
122 | 121 | return request.client
|
@@ -149,7 +148,7 @@ def client_authentication_required(self, request, *args, **kwargs):
|
149 | 148 |
|
150 | 149 | self._load_application(request.client_id, request)
|
151 | 150 | if request.client:
|
152 |
| - return request.client.client_type == Application.CLIENT_CONFIDENTIAL |
| 151 | + return request.client.client_type == AbstractApplication.CLIENT_CONFIDENTIAL |
153 | 152 |
|
154 | 153 | return super(OAuth2Validator, self).client_authentication_required(request,
|
155 | 154 | *args, **kwargs)
|
@@ -179,7 +178,7 @@ def authenticate_client_id(self, client_id, request, *args, **kwargs):
|
179 | 178 | """
|
180 | 179 | if self._load_application(client_id, request) is not None:
|
181 | 180 | log.debug("Application %s has type %s" % (client_id, request.client.client_type))
|
182 |
| - return request.client.client_type != Application.CLIENT_CONFIDENTIAL |
| 181 | + return request.client.client_type != AbstractApplication.CLIENT_CONFIDENTIAL |
183 | 182 | return False
|
184 | 183 |
|
185 | 184 | def confirm_redirect_uri(self, client_id, code, redirect_uri, client, *args, **kwargs):
|
@@ -253,9 +252,9 @@ def validate_response_type(self, client_id, response_type, client, request, *arg
|
253 | 252 | rfc:`8.4`, so validate the response_type only if it matches 'code' or 'token'
|
254 | 253 | """
|
255 | 254 | if response_type == 'code':
|
256 |
| - return client.authorization_grant_type == Application.GRANT_AUTHORIZATION_CODE |
| 255 | + return client.authorization_grant_type == AbstractApplication.GRANT_AUTHORIZATION_CODE |
257 | 256 | elif response_type == 'token':
|
258 |
| - return client.authorization_grant_type == Application.GRANT_IMPLICIT |
| 257 | + return client.authorization_grant_type == AbstractApplication.GRANT_IMPLICIT |
259 | 258 | else:
|
260 | 259 | return False
|
261 | 260 |
|
|
0 commit comments