Skip to content

Commit 26bc8ac

Browse files
author
Marc Michel
committed
oauth2 validator class from settings, refs issue #19
1 parent 5ef3dfb commit 26bc8ac

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

oauth2_provider/oauth2_backends.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from oauthlib.common import urlencode, urlencoded, quote
55

66
from .exceptions import OAuthToolkitError, FatalClientError
7-
from .oauth2_validators import OAuth2Validator
7+
from .settings import oauth2_settings
88
from .compat import urlparse, urlunparse
99

1010

@@ -16,7 +16,7 @@ def __init__(self, server=None):
1616
"""
1717
:params server: An instance of oauthlib.oauth2.Server class
1818
"""
19-
self.server = server or oauth2.Server(OAuth2Validator())
19+
self.server = server or oauth2.Server(oauth2_settings.OAUTH2_VALIDATOR_CLASS())
2020

2121
def _get_escaped_full_path(self, request):
2222
"""
@@ -80,7 +80,7 @@ def create_authorization_response(self, request, scopes, credentials, allow):
8080
if not allow:
8181
raise oauth2.AccessDeniedError()
8282

83-
# add current user to credentials. this will be used by OAuth2Validator
83+
# add current user to credentials. this will be used by OAUTH2_VALIDATOR_CLASS
8484
credentials['user'] = request.user
8585

8686
headers, body, status = self.server.create_authorization_response(
@@ -126,8 +126,7 @@ def get_oauthlib_core():
126126
Utility function that take a request and returns an instance of
127127
`oauth2_provider.backends.OAuthLibCore`
128128
"""
129-
from oauth2_provider.oauth2_validators import OAuth2Validator
130129
from oauthlib.oauth2 import Server
131130

132-
server = Server(OAuth2Validator())
131+
server = Server(oauth2_settings.OAUTH2_VALIDATOR_CLASS())
133132
return OAuthLibCore(server)

oauth2_provider/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
DEFAULTS = {
2929
'CLIENT_ID_GENERATOR_CLASS': 'oauth2_provider.generators.ClientIdGenerator',
3030
'CLIENT_SECRET_GENERATOR_CLASS': 'oauth2_provider.generators.ClientSecretGenerator',
31+
'OAUTH2_VALIDATOR_CLASS': 'oauth2_provider.oauth2_validators.OAuth2Validator',
3132
'SCOPES': {"read": "Reading scope", "write": "Writing scope"},
3233
'READ_SCOPE': 'read',
3334
'WRITE_SCOPE': 'write',
@@ -43,13 +44,15 @@
4344
MANDATORY = (
4445
'CLIENT_ID_GENERATOR_CLASS',
4546
'CLIENT_SECRET_GENERATOR_CLASS',
47+
'OAUTH2_VALIDATOR_CLASS',
4648
'SCOPES',
4749
)
4850

4951
# List of settings that may be in string import notation.
5052
IMPORT_STRINGS = (
5153
'CLIENT_ID_GENERATOR_CLASS',
5254
'CLIENT_SECRET_GENERATOR_CLASS',
55+
'OAUTH2_VALIDATOR_CLASS',
5356
)
5457

5558

0 commit comments

Comments
 (0)