Skip to content

Commit 1676942

Browse files
committed
Update oauth2_validators.py
1 parent 9aa27c7 commit 1676942

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ def validate_client_id(self, client_id, request, *args, **kwargs):
333333
def get_default_redirect_uri(self, client_id, request, *args, **kwargs):
334334
return request.client.default_redirect_uri
335335

336+
def get_or_create_user_from_content(self, content):
337+
"""
338+
An optional layer to define where to store the profile in `UserModel` or a separate model. For example `UserOAuth`, where `user = models.OneToOneField(UserModel)` .
339+
340+
The function is called after checking that username is in the content.
341+
342+
Returns an UserModel instance;
343+
"""
344+
user, _ = UserModel.objects.get_or_create(
345+
**{UserModel.USERNAME_FIELD: content["username"]}
346+
)
347+
return user
348+
336349
def _get_token_from_authentication_server(
337350
self, token, introspection_url, introspection_token, introspection_credentials
338351
):
@@ -383,9 +396,7 @@ def _get_token_from_authentication_server(
383396

384397
if "active" in content and content["active"] is True:
385398
if "username" in content:
386-
user, _created = UserModel.objects.get_or_create(
387-
**{UserModel.USERNAME_FIELD: content["username"]}
388-
)
399+
user = self.get_or_create_user_from_content(content)
389400
else:
390401
user = None
391402

0 commit comments

Comments
 (0)