Add oauth2client as a completely separate library.
Reviewed in http://codereview.appspot.com/4630079/
diff --git a/samples/appengine/main.py b/samples/appengine/main.py
index 087a136..184f5fa 100755
--- a/samples/appengine/main.py
+++ b/samples/appengine/main.py
@@ -36,6 +36,16 @@
from google.appengine.ext.webapp.util import login_required
+FLOW = OAuth2WebServerFlow(
+ # Visit https://code.google.com/apis/console to
+ # generate your client_id, client_secret and to
+ # register your redirect_uri.
+ client_id='<YOUR CLIENT ID HERE>',
+ client_secret='<YOUR CLIENT SECRET HERE>',
+ scope='https://www.googleapis.com/auth/buzz',
+ user_agent='buzz-cmdline-sample/1.0')
+
+
class Credentials(db.Model):
credentials = CredentialsProperty()
@@ -49,20 +59,9 @@
Credentials, user.user_id(), 'credentials').get()
if credentials is None or credentials.invalid == True:
- flow = OAuth2WebServerFlow(
- # Visit https://code.google.com/apis/console to
- # generate your client_id, client_secret and to
- # register your redirect_uri.
- client_id='<YOUR CLIENT ID HERE>',
- client_secret='<YOUR CLIENT SECRET HERE>',
- scope='https://www.googleapis.com/auth/buzz',
- user_agent='buzz-cmdline-sample/1.0',
- domain='anonymous',
- xoauth_displayname='Google App Engine Example App')
-
- callback = self.request.relative_url('/auth_return')
- authorize_url = flow.step1_get_authorize_url(callback)
- memcache.set(user.user_id(), pickle.dumps(flow))
+ callback = self.request.relative_url('/oauth2callback')
+ authorize_url = FLOW.step1_get_authorize_url(callback)
+ memcache.set(user.user_id(), pickle.dumps(FLOW))
self.redirect(authorize_url)
else:
http = httplib2.Http()
@@ -99,7 +98,7 @@
application = webapp.WSGIApplication(
[
('/', MainHandler),
- ('/auth_return', OAuthHandler)
+ ('/oauth2callback', OAuthHandler)
],
debug=True)
util.run_wsgi_app(application)
diff --git a/samples/oauth2/dailymotion/apiclient b/samples/oauth2/dailymotion/apiclient
deleted file mode 120000
index f53af07..0000000
--- a/samples/oauth2/dailymotion/apiclient
+++ /dev/null
@@ -1 +0,0 @@
-../../../apiclient/
\ No newline at end of file
diff --git a/samples/oauth2/dailymotion/main.py b/samples/oauth2/dailymotion/main.py
index c904e3b..1b75239 100644
--- a/samples/oauth2/dailymotion/main.py
+++ b/samples/oauth2/dailymotion/main.py
@@ -23,7 +23,6 @@
import os
import pickle
-from apiclient.discovery import build
from oauth2client.appengine import CredentialsProperty
from oauth2client.appengine import StorageByKeyName
from oauth2client.client import OAuth2WebServerFlow
@@ -36,6 +35,16 @@
from google.appengine.ext.webapp.util import login_required
+FLOW = OAuth2WebServerFlow(
+ client_id='2ad565600216d25d9cde',
+ client_secret='03b56df2949a520be6049ff98b89813f17b467dc',
+ scope='read',
+ user_agent='oauth2client-sample/1.0',
+ auth_uri='https://api.dailymotion.com/oauth/authorize',
+ token_uri='https://api.dailymotion.com/oauth/token'
+ )
+
+
class Credentials(db.Model):
credentials = CredentialsProperty()
@@ -49,37 +58,23 @@
Credentials, user.user_id(), 'credentials').get()
if credentials is None or credentials.invalid == True:
- flow = OAuth2WebServerFlow(
- client_id='2ad565600216d25d9cde',
- client_secret='03b56df2949a520be6049ff98b89813f17b467dc',
- scope='read',
- user_agent='oauth2client-sample/1.0',
- auth_uri='https://api.dailymotion.com/oauth/authorize',
- token_uri='https://api.dailymotion.com/oauth/token'
- )
-
callback = self.request.relative_url('/auth_return')
- authorize_url = flow.step1_get_authorize_url(callback)
- memcache.set(user.user_id(), pickle.dumps(flow))
+ authorize_url = FLOW.step1_get_authorize_url(callback)
+ memcache.set(user.user_id(), pickle.dumps(FLOW))
self.redirect(authorize_url)
else:
http = httplib2.Http()
-
- resp, content1 = http.request('https://api.dailymotion.com/me?access_token=%s' %
- credentials.access_token)
-
http = credentials.authorize(http)
- resp, content2 = http.request('https://api.dailymotion.com/me')
+
+ resp, content = http.request('https://api.dailymotion.com/me')
path = os.path.join(os.path.dirname(__file__), 'welcome.html')
logout = users.create_logout_url('/')
- self.response.out.write(
- template.render(
- path, {
- 'content1': content1,
- 'content2': content2,
- 'logout': logout
- }))
+ variables = {
+ 'content': content,
+ 'logout': logout
+ }
+ self.response.out.write(template.render(path, variables))
class OAuthHandler(webapp.RequestHandler):
diff --git a/samples/oauth2/dailymotion/welcome.html b/samples/oauth2/dailymotion/welcome.html
index 06fcb95..f86902f 100644
--- a/samples/oauth2/dailymotion/welcome.html
+++ b/samples/oauth2/dailymotion/welcome.html
@@ -8,9 +8,7 @@
</head>
<body>
<p><a href="{{ logout }}">Logout</a></p>
- <h2>First request with access_token in query parameter:</h2>
- <pre>{{ content1 }} </pre>
- <h2>Second request with access_token in header:</h2>
- <pre>{{ content2 }} </pre>
+ <h2>Response body:</h2>
+ <pre>{{ content }} </pre>
</body>
</html>
diff --git a/samples/oauth2/django_sample/buzz/views.py b/samples/oauth2/django_sample/buzz/views.py
index c942aaf..9a051ea 100644
--- a/samples/oauth2/django_sample/buzz/views.py
+++ b/samples/oauth2/django_sample/buzz/views.py
@@ -16,22 +16,21 @@
from django.shortcuts import render_to_response
STEP2_URI = 'http://localhost:8000/auth_return'
-
+FLOW = OAuth2WebServerFlow(
+ client_id='837647042410.apps.googleusercontent.com',
+ client_secret='+SWwMCL9d8gWtzPRa1lXw5R8',
+ scope='https://www.googleapis.com/auth/buzz',
+ user_agent='buzz-django-sample/1.0',
+ )
@login_required
def index(request):
storage = Storage(CredentialsModel, 'id', request.user, 'credential')
credential = storage.get()
if credential is None or credential.invalid == True:
- flow = OAuth2WebServerFlow(
- client_id='837647042410.apps.googleusercontent.com',
- client_secret='+SWwMCL9d8gWtzPRa1lXw5R8',
- scope='https://www.googleapis.com/auth/buzz',
- user_agent='buzz-django-sample/1.0',
- )
- authorize_url = flow.step1_get_authorize_url(STEP2_URI)
- f = FlowModel(id=request.user, flow=flow)
+ authorize_url = FLOW.step1_get_authorize_url(STEP2_URI)
+ f = FlowModel(id=request.user, flow=FLOW)
f.save()
return HttpResponseRedirect(authorize_url)
else: