From 0fb2d27be1a3ba2e70376b408d8bc22bf01e4798 Mon Sep 17 00:00:00 2001 From: Sharad Heft Date: Mon, 6 Nov 2017 00:03:10 +0100 Subject: [PATCH] Refactor some of the profile retrieval code. --- test_oauth/backend.py | 11 +++++++---- test_oauth/views.py | 4 +--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test_oauth/backend.py b/test_oauth/backend.py index e7bd348..081f477 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 b471749..ae82c2a 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', '/')) -- GitLab