Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions samples/django_sample/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pip:
@pip install -r requirements.txt


syncdb:
@python manage.py syncdb


run:
@python manage.py runserver 0.0.0.0:8000


setup: pip syncdb run


shell:
@python manage.py shell


test:
@python manage.py test
2 changes: 1 addition & 1 deletion samples/django_sample/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import
from django.core.management import execute_manager
try:
from . import settings # Assumed to be in the same directory.
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("""Error: Can't find the file 'settings.py' in the
Expand Down
9 changes: 1 addition & 8 deletions samples/django_sample/plus/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import pickle
import base64

from django.contrib import admin
from django.contrib.auth.models import User
from django.db import models

from oauth2client.contrib.django_orm import FlowField
from oauth2client.contrib.django_orm import CredentialsField
from oauth2client.contrib.django_util.models import CredentialsField


class CredentialsModel(models.Model):
Expand All @@ -16,6 +12,3 @@ class CredentialsModel(models.Model):

class CredentialsAdmin(admin.ModelAdmin):
pass


admin.site.register(CredentialsModel, CredentialsAdmin)
11 changes: 4 additions & 7 deletions samples/django_sample/plus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,29 @@

from googleapiclient.discovery import build
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.http import HttpResponseBadRequest
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django_sample.plus.models import CredentialsModel
from django_sample import settings
from oauth2client.contrib import xsrfutil
from oauth2client.client import flow_from_clientsecrets
from oauth2client.contrib.django_orm import Storage
from oauth2client.contrib.django_util.storage import DjangoORMStorage

# CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this
# application, including client_id and client_secret, which are found
# on the API Access tab on the Google APIs
# Console <http://code.google.com/apis/console>
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), '..', 'client_secrets.json')

FLOW = flow_from_clientsecrets(
CLIENT_SECRETS,
settings.GOOGLE_OAUTH2_CLIENT_SECRETS_JSON,
scope='https://www.googleapis.com/auth/plus.me',
redirect_uri='http://localhost:8000/oauth2callback')


@login_required
def index(request):
storage = Storage(CredentialsModel, 'id', request.user, 'credential')
storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
credential = storage.get()
if credential is None or credential.invalid == True:
FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY,
Expand All @@ -56,6 +53,6 @@ def auth_return(request):
request.user):
return HttpResponseBadRequest()
credential = FLOW.step2_exchange(request.REQUEST)
storage = Storage(CredentialsModel, 'id', request.user, 'credential')
storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
storage.put(credential)
return HttpResponseRedirect("/")
11 changes: 11 additions & 0 deletions samples/django_sample/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Django==1.3
google-api-python-client==1.6.2
httplib2==0.10.3
jsonpickle==0.9.4
oauth2client==4.1.2
pyasn1==0.2.3
pyasn1-modules==0.0.9
pytz==2017.2
rsa==3.4.2
six==1.10.0
uritemplate==3.0.0
4 changes: 3 additions & 1 deletion samples/django_sample/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,7 @@
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django_sample.plus'
'plus'
)

GOOGLE_OAUTH2_CLIENT_SECRETS_JSON = 'client_secrets.json'