some cleanup
This commit is contained in:
parent
f1cec16495
commit
60527d18c3
4 changed files with 44 additions and 42 deletions
|
|
@ -5,6 +5,7 @@ GOOYAL_DEFAULTS = {
|
|||
"RESOURCE_SERVER_CLIENT_ID": None,
|
||||
"RESOURCE_SERVER_CLIENT_SECRET": None,
|
||||
|
||||
# set default
|
||||
"INTROSPECTION_USER_CREATE_METHOD": None,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,47 +16,6 @@ AccessTokenModel = get_access_token_model()
|
|||
UserModel = get_user_model()
|
||||
|
||||
|
||||
def get_user_profile(token, content):
|
||||
# content = {
|
||||
# "active": True,
|
||||
# "scope": "read write email",
|
||||
# "client_id": "J8NFmU4tJVgDxKaJFmXTWvaHO",
|
||||
# "username": "aaronpk",
|
||||
# "exp": 1437275311
|
||||
# }
|
||||
|
||||
user_client = service_clients.Client(access_token=token,
|
||||
scopes=content.get('scope', '').split(),
|
||||
expires_in=100)
|
||||
|
||||
user_account = user_client.accounts.account()
|
||||
if user_account.get('uuid'):
|
||||
content.update(user_account)
|
||||
|
||||
# content = {'active': True, 'scope': 'ipg.payment:submit accounts.account:retrieve', 'exp': 1602619137,
|
||||
# 'client_id': 'bd2hEGXytrqMjbFnplRyHJTeoW1vwKzCZJtH6ro0', 'username': '',
|
||||
# 'uuid': '94255117-117c-4a9f-af50-35a6c47503ac', 'email': '', 'phone_number': '+989106853582',
|
||||
# 'first_name': '', 'last_name': '', 'name': '', 'balance': 0,
|
||||
# 'avatar': 'http://accounts.gooyal.com/media/avatars/1691899.jpg', 'iban': '', 'iban_verified': None}
|
||||
|
||||
user = UserModel.objects.filter(uuid=content['uuid']).first()
|
||||
if user:
|
||||
pass
|
||||
|
||||
else:
|
||||
user = UserModel.objects.create_user(
|
||||
**{UserModel.USERNAME_FIELD: content["username"]},
|
||||
uuid=content['uuid'],
|
||||
email=content['email'],
|
||||
phone_number=content['phone_number'],
|
||||
first_name=content['first_name'],
|
||||
last_name=content['last_name'],
|
||||
name=content['name'],
|
||||
avatar=content['avatar']
|
||||
)
|
||||
return user, content
|
||||
|
||||
|
||||
class OAuth2Validator(BaseOAuth2Validator): # pylint: disable=w0223
|
||||
def validate_user(self, username, password, client, request, *args, **kwargs):
|
||||
auth_fields = getattr(request, 'auth_fields', 'username:password').split(':')
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import random
|
||||
from datetime import timedelta
|
||||
|
||||
import service_clients
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.base_user import BaseUserManager
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
|
|
@ -178,3 +179,44 @@ class User(AbstractUser):
|
|||
|
||||
def __str__(self):
|
||||
return f"{self.pk} - {self.username}"
|
||||
|
||||
|
||||
def create_user_in_introspection(token, content):
|
||||
# content = {
|
||||
# "active": True,
|
||||
# "scope": "read write email",
|
||||
# "client_id": "J8NFmU4tJVgDxKaJFmXTWvaHO",
|
||||
# "username": "aaronpk",
|
||||
# "exp": 1437275311
|
||||
# }
|
||||
|
||||
user_client = service_clients.Client(access_token=token,
|
||||
scopes=content.get('scope', '').split(),
|
||||
expires_in=100)
|
||||
|
||||
user_account = user_client.accounts.account()
|
||||
if user_account.get('uuid'):
|
||||
content.update(user_account)
|
||||
|
||||
# content = {'active': True, 'scope': 'ipg.payment:submit accounts.account:retrieve', 'exp': 1602619137,
|
||||
# 'client_id': 'bd2hEGXytrqMjbFnplRyHJTeoW1vwKzCZJtH6ro0', 'username': '',
|
||||
# 'uuid': '94255117-117c-4a9f-af50-35a6c47503ac', 'email': '', 'phone_number': '+989106853582',
|
||||
# 'first_name': '', 'last_name': '', 'name': '', 'balance': 0,
|
||||
# 'avatar': 'http://accounts.gooyal.com/media/avatars/1691899.jpg', 'iban': '', 'iban_verified': None}
|
||||
|
||||
user = User.objects.filter(uuid=content['uuid']).first()
|
||||
if user:
|
||||
pass
|
||||
|
||||
else:
|
||||
user = User.objects.create_user(
|
||||
**{User.USERNAME_FIELD: content["username"]},
|
||||
uuid=content['uuid'],
|
||||
email=content['email'],
|
||||
phone_number=content['phone_number'],
|
||||
first_name=content['first_name'],
|
||||
last_name=content['last_name'],
|
||||
name=content['name'],
|
||||
avatar=content['avatar']
|
||||
)
|
||||
return user, content
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ OAUTH2_PROVIDER = {
|
|||
'groups': 'Access to your groups',
|
||||
'introspection': 'Introspect token scope'},
|
||||
'OAUTH2_VALIDATOR_CLASS': 'apps.gooyal_oauth2.validators.OAuth2Validator',
|
||||
"INTROSPECTION_USER_CREATE_METHOD": 'apps.gooyal_oauth2.validators.get_user_profile',
|
||||
"INTROSPECTION_USER_CREATE_METHOD": 'apps.users.models.create_user_in_introspection',
|
||||
}
|
||||
|
||||
# GOOYAL_DYNAMIC_SCOPES
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue