Commit 0fb2d27b authored by Sharad Heft's avatar Sharad Heft

Refactor some of the profile retrieval code.

parent 8b5c4705
...@@ -6,16 +6,19 @@ from django.db import transaction ...@@ -6,16 +6,19 @@ from django.db import transaction
from test_oauth.models import TESTOAuth2Data, Character from test_oauth.models import TESTOAuth2Data, Character
from test_oauth.session import TESTOAuth2Session
class TESTOAuth2Backend(ModelBackend): class TESTOAuth2Backend(ModelBackend):
def authenticate(self, token=None, id=None, username=None, **profile): def authenticate(self, token=None, **kwargs):
if id is None or username is None or token is None: if token is None:
return None return None
profile = TESTOAuth2Session(token=token).profile
user, _ = get_user_model().objects.get_or_create( user, _ = get_user_model().objects.get_or_create(
pk=id, pk=profile['id'],
username=username username=profile['username']
) )
data, _ = TESTOAuth2Data.objects.update_or_create( data, _ = TESTOAuth2Data.objects.update_or_create(
......
...@@ -29,8 +29,6 @@ def callback(request): ...@@ -29,8 +29,6 @@ def callback(request):
.fetch_token(code=request.GET['code']) .fetch_token(code=request.GET['code'])
) )
session = TESTOAuth2Session(token=token) auth.login(request, auth.authenticate(token=token))
auth.login(request, auth.authenticate(token=token, **session.profile))
return redirect(getattr(settings, 'TEST_OAUTH_REDIRECT', '/')) return redirect(getattr(settings, 'TEST_OAUTH_REDIRECT', '/'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment