diff --git a/test_oauth/backend.py b/test_oauth/backend.py index e7bd3489bb5811e9b9997194c289d8022b1c841b..081f4773a354748baa3c86cefe3fcf6eedda9df4 100644 --- a/test_oauth/backend.py +++ b/test_oauth/backend.py @@ -6,16 +6,19 @@ from django.db import transaction from test_oauth.models import TESTOAuth2Data, Character +from test_oauth.session import TESTOAuth2Session class TESTOAuth2Backend(ModelBackend): - def authenticate(self, token=None, id=None, username=None, **profile): - if id is None or username is None or token is None: + def authenticate(self, token=None, **kwargs): + if token is None: return None + profile = TESTOAuth2Session(token=token).profile + user, _ = get_user_model().objects.get_or_create( - pk=id, - username=username + pk=profile['id'], + username=profile['username'] ) data, _ = TESTOAuth2Data.objects.update_or_create( diff --git a/test_oauth/views.py b/test_oauth/views.py index b471749913e6e5f1c124d6b06094c1c0c6e4759a..ae82c2ad2363e53504f15f41372df436b55b3c35 100644 --- a/test_oauth/views.py +++ b/test_oauth/views.py @@ -29,8 +29,6 @@ def callback(request): .fetch_token(code=request.GET['code']) ) - session = TESTOAuth2Session(token=token) - - auth.login(request, auth.authenticate(token=token, **session.profile)) + auth.login(request, auth.authenticate(token=token)) return redirect(getattr(settings, 'TEST_OAUTH_REDIRECT', '/'))