Skip to content

Commit

Permalink
Modify mock OAuth to allow users to run as themselves locally
Browse files Browse the repository at this point in the history
  • Loading branch information
durden committed Jul 31, 2011
1 parent bd97890 commit 0a29d58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 9 additions & 6 deletions apps/codrspace/mock_views.py
@@ -1,14 +1,15 @@
"""Mock views for testing OAuth with Github API locally"""


import random

from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.shortcuts import redirect

token = "1c21852a9f19b685d6f67f4409b5b4980a0c9d4f"
code = 100
try:
from local_settings import GITHUB_API_TOKEN
except ImportError:
# Will always authenticate as 'durden' and only for codrspace app
GITHUB_API_TOKEN = "1c21852a9f19b685d6f67f4409b5b4980a0c9d4f"


def authorize(request):
Expand All @@ -17,6 +18,8 @@ def authorize(request):
if 'client_id' not in request.GET:
raise Exception("Authorize must specify client_id")

# Just send some code back, doesn't matter for testing
code = 100
return redirect("%s?code=%d" % (reverse('signin_callback'), code))


Expand All @@ -35,5 +38,5 @@ def access_token(request):
if 'code' not in request.POST:
raise Exception("Authorize must specify code")

return HttpResponse("access_token=%s&token_type=bearer" % (token),
mimetype="text/plain")
return HttpResponse("access_token=%s&token_type=bearer" % (
GITHUB_API_TOKEN), mimetype="text/plain")
9 changes: 9 additions & 0 deletions example_local_settings.py
Expand Up @@ -23,6 +23,15 @@ def get_setting(setting):
DEBUG = True
TEMPLATE_DEBUG = DEBUG

# You can get this token from github.com by doing the following:
# - Login to your account
# - Click 'Account Settings' at top
# - Click 'Account Admin' on left (middle of page
# - Copy/paste token under 'API Token' section below

# Replace with your own github API token to run locally and have faked OAuth
# instance always authorize as you
#GITHUB_API_TOKEN = ''

# Overrides for middleware to avoid having the CSRF protection when running
# locally
Expand Down

0 comments on commit 0a29d58

Please sign in to comment.