fix GitHub Pretend throwing a 500 error

This commit is contained in:
Jens Langhammer 2019-03-13 15:12:13 +01:00
parent 67b19becc1
commit 70c11c8988
1 changed files with 14 additions and 6 deletions

View File

@ -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,