30 lines
1 KiB
Python
Executable file
30 lines
1 KiB
Python
Executable file
import base64
|
|
import binascii
|
|
import logging
|
|
from datetime import datetime, timedelta
|
|
from urllib.parse import unquote_plus
|
|
|
|
import requests
|
|
# import service_clients
|
|
from django.contrib.auth import get_user_model
|
|
from django.utils.timezone import make_aware
|
|
from oauth2_provider.models import get_access_token_model
|
|
from oauth2_provider.oauth2_validators import OAuth2Validator as BaseOAuth2Validator
|
|
|
|
log = logging.getLogger("oauth2_provider")
|
|
|
|
AccessTokenModel = get_access_token_model()
|
|
UserModel = get_user_model()
|
|
|
|
class OAuth2Validator(BaseOAuth2Validator): # pylint: disable=w0223
|
|
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(pk=content["username"])
|
|
return user
|