44
55from googleapiclient .discovery import build
66from django .contrib .auth .decorators import login_required
7- from django .core .urlresolvers import reverse
8- from django .http import HttpResponse
97from django .http import HttpResponseBadRequest
108from django .http import HttpResponseRedirect
119from django .shortcuts import render
1210from django_sample .plus .models import CredentialsModel
1311from django_sample import settings
1412from oauth2client .contrib import xsrfutil
1513from oauth2client .client import flow_from_clientsecrets
16- from oauth2client .contrib .django_orm import Storage
14+ from oauth2client .contrib .django_util . storage import DjangoORMStorage
1715
1816# CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this
1917# application, including client_id and client_secret, which are found
2018# on the API Access tab on the Google APIs
2119# Console <http://code.google.com/apis/console>
22- CLIENT_SECRETS = os .path .join (os .path .dirname (__file__ ), '..' , 'client_secrets.json' )
2320
2421FLOW = flow_from_clientsecrets (
25- CLIENT_SECRETS ,
22+ settings . GOOGLE_OAUTH2_CLIENT_SECRETS_JSON ,
2623 scope = 'https://www.googleapis.com/auth/plus.me' ,
2724 redirect_uri = 'http://localhost:8000/oauth2callback' )
2825
2926
3027@login_required
3128def index (request ):
32- storage = Storage (CredentialsModel , 'id' , request .user , 'credential' )
29+ storage = DjangoORMStorage (CredentialsModel , 'id' , request .user , 'credential' )
3330 credential = storage .get ()
3431 if credential is None or credential .invalid == True :
3532 FLOW .params ['state' ] = xsrfutil .generate_token (settings .SECRET_KEY ,
@@ -56,6 +53,6 @@ def auth_return(request):
5653 request .user ):
5754 return HttpResponseBadRequest ()
5855 credential = FLOW .step2_exchange (request .REQUEST )
59- storage = Storage (CredentialsModel , 'id' , request .user , 'credential' )
56+ storage = DjangoORMStorage (CredentialsModel , 'id' , request .user , 'credential' )
6057 storage .put (credential )
6158 return HttpResponseRedirect ("/" )
0 commit comments