Skip to content

Commit

Permalink
Update oauth2_validators.py
Browse files Browse the repository at this point in the history
  • Loading branch information
1vank1n committed May 13, 2024
1 parent 2ef14c5 commit 4dd200c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions oauth2_provider/oauth2_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,19 @@ def validate_client_id(self, client_id, request, *args, **kwargs):
def get_default_redirect_uri(self, client_id, request, *args, **kwargs):
return request.client.default_redirect_uri

def get_or_create_user_from_content(self, content):
"""
An optional layer to define where to store the profile in `UserModel` or a separate model. For example `UserOAuth`, where `user = models.OneToOneField(UserModel)` .
The function is called after checking that username is in the content.
Returns an UserModel instance;
"""
user, _ = UserModel.objects.get_or_create(
**{UserModel.USERNAME_FIELD: content["username"]}
)
return user

def _get_token_from_authentication_server(
self, token, introspection_url, introspection_token, introspection_credentials
):
Expand Down Expand Up @@ -383,9 +396,7 @@ def _get_token_from_authentication_server(

if "active" in content and content["active"] is True:
if "username" in content:
user, _created = UserModel.objects.get_or_create(
**{UserModel.USERNAME_FIELD: content["username"]}
)
user = self.get_or_create_user_from_content(content)
else:
user = None

Expand Down

0 comments on commit 4dd200c

Please sign in to comment.