From 70c11c898820113a097ac9ae7661f8d0883f1983 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 13 Mar 2019 15:12:13 +0100 Subject: [PATCH] fix GitHub Pretend throwing a 500 error --- passbook/pretend/views/github.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/passbook/pretend/views/github.py b/passbook/pretend/views/github.py index 42a7d3a07..bed4c770d 100644 --- a/passbook/pretend/views/github.py +++ b/passbook/pretend/views/github.py @@ -1,16 +1,24 @@ """passbook pretend GitHub Views""" from django.http import JsonResponse +from django.shortcuts import get_object_or_404 from django.views import View +from oauth2_provider.models import AccessToken class GitHubUserView(View): """Emulate GitHub's /user API Endpoint""" + def verify_access_token(self): + """Verify access token manually since github uses /user?access_token=...""" + token = get_object_or_404(AccessToken, token=self.request.get('access_token', '')) + return token.user + def get(self, request): """Emulate GitHub's /user API Endpoint""" + user = self.verify_access_token() return JsonResponse({ - "login": request.user.username, - "id": request.user.pk, + "login": user.username, + "id": user.pk, "node_id": "", "avatar_url": "", "gravatar_id": "", @@ -27,19 +35,19 @@ class GitHubUserView(View): "received_events_url": "", "type": "User", "site_admin": False, - "name": request.user.name, + "name": user.name, "company": "", "blog": "", "location": "", - "email": request.user.email, + "email": user.email, "hireable": False, "bio": "", "public_repos": 0, "public_gists": 0, "followers": 0, "following": 0, - "created_at": request.user.date_joined, - "updated_at": request.user.date_joined, + "created_at": user.date_joined, + "updated_at": user.date_joined, "private_gists": 0, "total_private_repos": 0, "owned_private_repos": 0,