Added placeholder samples for the oauth2decorator.
This commit is contained in:
1
samples/appengine_with_decorator/apiclient
Symbolic link
1
samples/appengine_with_decorator/apiclient
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../appengine/apiclient
|
||||||
12
samples/appengine_with_decorator/app.yaml
Normal file
12
samples/appengine_with_decorator/app.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
application: jcg-testing-01
|
||||||
|
version: 1
|
||||||
|
runtime: python
|
||||||
|
api_version: 1
|
||||||
|
|
||||||
|
handlers:
|
||||||
|
- url: /oauth2callback
|
||||||
|
script: oauth2client/appengine.py
|
||||||
|
|
||||||
|
- url: .*
|
||||||
|
script: main.py
|
||||||
|
|
||||||
92
samples/appengine_with_decorator/better.py
Normal file
92
samples/appengine_with_decorator/better.py
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# Copyright 2007 Google Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
"""Starting template for Google App Engine applications.
|
||||||
|
|
||||||
|
Use this project as a starting point if you are just beginning to build a Google
|
||||||
|
App Engine project. Remember to fill in the OAuth 2.0 client_id and
|
||||||
|
client_secret which can be obtained from the Developer Console
|
||||||
|
<https://code.google.com/apis/console/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||||
|
|
||||||
|
|
||||||
|
import httplib2
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
from apiclient.discovery import build
|
||||||
|
from oauth2client.appengine import OAuth2Decorator
|
||||||
|
from oauth2client.client import AccessTokenRefreshError
|
||||||
|
from google.appengine.api import memcache
|
||||||
|
from google.appengine.ext import webapp
|
||||||
|
from google.appengine.ext.webapp import template
|
||||||
|
from google.appengine.ext.webapp.util import run_wsgi_app
|
||||||
|
|
||||||
|
# The client_id and client_secret are copied from the API Access tab on
|
||||||
|
# the Google APIs Console <http://code.google.com/apis/console>
|
||||||
|
decorator = OAuth2Decorator(
|
||||||
|
client_id='837647042410-75ifgipj95q4agpm0cs452mg7i2pn17c.apps.googleusercontent.com',
|
||||||
|
client_secret='QhxYsjM__u4vy5N0DXUFRwwI',
|
||||||
|
scope='https://www.googleapis.com/auth/buzz',
|
||||||
|
user_agent='my-sample-app/1.0')
|
||||||
|
|
||||||
|
http = httplib2.Http(memcache)
|
||||||
|
service = build("buzz", "v1", http=http)
|
||||||
|
|
||||||
|
|
||||||
|
class MainHandler(webapp.RequestHandler):
|
||||||
|
|
||||||
|
@decorator.oauth_aware
|
||||||
|
def get(self):
|
||||||
|
path = os.path.join(os.path.dirname(__file__), 'grant.html')
|
||||||
|
variables = {
|
||||||
|
'url': decorator.authorize_url(),
|
||||||
|
'has_credentials': decorator.has_credentials()
|
||||||
|
}
|
||||||
|
self.response.out.write(template.render(path, variables))
|
||||||
|
|
||||||
|
|
||||||
|
class FollowerHandler(webapp.RequestHandler):
|
||||||
|
|
||||||
|
@decorator.oauth_required
|
||||||
|
def get(self):
|
||||||
|
try:
|
||||||
|
http = decorator.http()
|
||||||
|
followers = service.people().list(
|
||||||
|
userId='@me', groupId='@followers').execute(http)
|
||||||
|
text = 'Hello, you have %s followers!' % followers['totalResults']
|
||||||
|
|
||||||
|
path = os.path.join(os.path.dirname(__file__), 'welcome.html')
|
||||||
|
self.response.out.write(template.render(path, {'text': text }))
|
||||||
|
except AccessTokenRefreshError:
|
||||||
|
self.redirect('/')
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
application = webapp.WSGIApplication(
|
||||||
|
[
|
||||||
|
('/', MainHandler),
|
||||||
|
('/followers', FollowerHandler),
|
||||||
|
],
|
||||||
|
debug=True)
|
||||||
|
run_wsgi_app(application)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
1
samples/appengine_with_decorator/gflags.py
Symbolic link
1
samples/appengine_with_decorator/gflags.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../gflags.py
|
||||||
1
samples/appengine_with_decorator/gflags_validators.py
Symbolic link
1
samples/appengine_with_decorator/gflags_validators.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../gflags_validators.py
|
||||||
1
samples/appengine_with_decorator/httplib2
Symbolic link
1
samples/appengine_with_decorator/httplib2
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../appengine/httplib2
|
||||||
11
samples/appengine_with_decorator/index.yaml
Normal file
11
samples/appengine_with_decorator/index.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
indexes:
|
||||||
|
|
||||||
|
# AUTOGENERATED
|
||||||
|
|
||||||
|
# This index.yaml is automatically updated whenever the dev_appserver
|
||||||
|
# detects that a new type of query is run. If you want to manage the
|
||||||
|
# index.yaml file manually, remove the above marker line (the line
|
||||||
|
# saying "# AUTOGENERATED"). If you want to manage some indexes
|
||||||
|
# manually, move them above the marker line. The index.yaml file is
|
||||||
|
# automatically uploaded to the admin console when you next deploy
|
||||||
|
# your application using appcfg.py.
|
||||||
70
samples/appengine_with_decorator/main.py
Executable file
70
samples/appengine_with_decorator/main.py
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# Copyright 2007 Google Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
"""Starting template for Google App Engine applications.
|
||||||
|
|
||||||
|
Use this project as a starting point if you are just beginning to build a Google
|
||||||
|
App Engine project. Remember to fill in the OAuth 2.0 client_id and
|
||||||
|
client_secret which can be obtained from the Developer Console
|
||||||
|
<https://code.google.com/apis/console/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||||
|
|
||||||
|
|
||||||
|
import httplib2
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
from apiclient.discovery import build
|
||||||
|
from oauth2client.appengine import OAuth2Decorator
|
||||||
|
from google.appengine.api import memcache
|
||||||
|
from google.appengine.ext import webapp
|
||||||
|
from google.appengine.ext.webapp.util import run_wsgi_app
|
||||||
|
|
||||||
|
# The client_id and client_secret are copied from the API Access tab on
|
||||||
|
# the Google APIs Console <http://code.google.com/apis/console>
|
||||||
|
decorator = OAuth2Decorator(
|
||||||
|
client_id='837647042410-75ifgipj95q4agpm0cs452mg7i2pn17c.apps.googleusercontent.com',
|
||||||
|
client_secret='QhxYsjM__u4vy5N0DXUFRwwI',
|
||||||
|
scope='https://www.googleapis.com/auth/buzz',
|
||||||
|
user_agent='my-sample-app/1.0')
|
||||||
|
|
||||||
|
http = httplib2.Http(memcache)
|
||||||
|
service = build("buzz", "v1", http=http)
|
||||||
|
|
||||||
|
class MainHandler(webapp.RequestHandler):
|
||||||
|
|
||||||
|
@decorator.oauth_required
|
||||||
|
def get(self):
|
||||||
|
http = decorator.http()
|
||||||
|
followers = service.people().list(
|
||||||
|
userId='@me', groupId='@followers').execute(http)
|
||||||
|
self.response.out.write(
|
||||||
|
'Hello, you have %s followers!' % followers['totalResults'])
|
||||||
|
|
||||||
|
def main():
|
||||||
|
application = webapp.WSGIApplication(
|
||||||
|
[
|
||||||
|
('/', MainHandler),
|
||||||
|
],
|
||||||
|
debug=True)
|
||||||
|
run_wsgi_app(application)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
1
samples/appengine_with_decorator/oauth2
Symbolic link
1
samples/appengine_with_decorator/oauth2
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../appengine/oauth2
|
||||||
1
samples/appengine_with_decorator/oauth2client
Symbolic link
1
samples/appengine_with_decorator/oauth2client
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../oauth2client/
|
||||||
1
samples/appengine_with_decorator/uritemplate
Symbolic link
1
samples/appengine_with_decorator/uritemplate
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../appengine/uritemplate
|
||||||
1
samples/appengine_with_decorator2/apiclient
Symbolic link
1
samples/appengine_with_decorator2/apiclient
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../appengine/apiclient
|
||||||
12
samples/appengine_with_decorator2/app.yaml
Normal file
12
samples/appengine_with_decorator2/app.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
application: jcg-testing-01
|
||||||
|
version: 1
|
||||||
|
runtime: python
|
||||||
|
api_version: 1
|
||||||
|
|
||||||
|
handlers:
|
||||||
|
- url: /oauth2callback
|
||||||
|
script: oauth2client/appengine.py
|
||||||
|
|
||||||
|
- url: .*
|
||||||
|
script: main.py
|
||||||
|
|
||||||
1
samples/appengine_with_decorator2/gflags.py
Symbolic link
1
samples/appengine_with_decorator2/gflags.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../gflags.py
|
||||||
1
samples/appengine_with_decorator2/gflags_validators.py
Symbolic link
1
samples/appengine_with_decorator2/gflags_validators.py
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../gflags_validators.py
|
||||||
17
samples/appengine_with_decorator2/grant.html
Normal file
17
samples/appengine_with_decorator2/grant.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Can Haz Perms?</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% if has_credentials %}
|
||||||
|
<p>Thanks for granting us permission. Please <a href="/followers">proceed to the main
|
||||||
|
application</a>.</p>
|
||||||
|
{% else %}
|
||||||
|
<p><a href="{{ url }}">Grant</a> this application permission to read your
|
||||||
|
Buzz information and it will let you know how many followers you have.</p>
|
||||||
|
{% endif %}
|
||||||
|
<p>You can always <a
|
||||||
|
href="https://www.google.com/accounts/b/0/IssuedAuthSubTokens">revoke</a>
|
||||||
|
permission at any time.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
samples/appengine_with_decorator2/httplib2
Symbolic link
1
samples/appengine_with_decorator2/httplib2
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../appengine/httplib2
|
||||||
11
samples/appengine_with_decorator2/index.yaml
Normal file
11
samples/appengine_with_decorator2/index.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
indexes:
|
||||||
|
|
||||||
|
# AUTOGENERATED
|
||||||
|
|
||||||
|
# This index.yaml is automatically updated whenever the dev_appserver
|
||||||
|
# detects that a new type of query is run. If you want to manage the
|
||||||
|
# index.yaml file manually, remove the above marker line (the line
|
||||||
|
# saying "# AUTOGENERATED"). If you want to manage some indexes
|
||||||
|
# manually, move them above the marker line. The index.yaml file is
|
||||||
|
# automatically uploaded to the admin console when you next deploy
|
||||||
|
# your application using appcfg.py.
|
||||||
92
samples/appengine_with_decorator2/main.py
Normal file
92
samples/appengine_with_decorator2/main.py
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# Copyright 2007 Google Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
"""Starting template for Google App Engine applications.
|
||||||
|
|
||||||
|
Use this project as a starting point if you are just beginning to build a Google
|
||||||
|
App Engine project. Remember to fill in the OAuth 2.0 client_id and
|
||||||
|
client_secret which can be obtained from the Developer Console
|
||||||
|
<https://code.google.com/apis/console/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||||
|
|
||||||
|
|
||||||
|
import httplib2
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
from apiclient.discovery import build
|
||||||
|
from oauth2client.appengine import OAuth2Decorator
|
||||||
|
from oauth2client.client import AccessTokenRefreshError
|
||||||
|
from google.appengine.api import memcache
|
||||||
|
from google.appengine.ext import webapp
|
||||||
|
from google.appengine.ext.webapp import template
|
||||||
|
from google.appengine.ext.webapp.util import run_wsgi_app
|
||||||
|
|
||||||
|
# The client_id and client_secret are copied from the API Access tab on
|
||||||
|
# the Google APIs Console <http://code.google.com/apis/console>
|
||||||
|
decorator = OAuth2Decorator(
|
||||||
|
client_id='837647042410-75ifgipj95q4agpm0cs452mg7i2pn17c.apps.googleusercontent.com',
|
||||||
|
client_secret='QhxYsjM__u4vy5N0DXUFRwwI',
|
||||||
|
scope='https://www.googleapis.com/auth/buzz',
|
||||||
|
user_agent='my-sample-app/1.0')
|
||||||
|
|
||||||
|
http = httplib2.Http(memcache)
|
||||||
|
service = build("buzz", "v1", http=http)
|
||||||
|
|
||||||
|
|
||||||
|
class MainHandler(webapp.RequestHandler):
|
||||||
|
|
||||||
|
@decorator.oauth_aware
|
||||||
|
def get(self):
|
||||||
|
path = os.path.join(os.path.dirname(__file__), 'grant.html')
|
||||||
|
variables = {
|
||||||
|
'url': decorator.authorize_url(),
|
||||||
|
'has_credentials': decorator.has_credentials()
|
||||||
|
}
|
||||||
|
self.response.out.write(template.render(path, variables))
|
||||||
|
|
||||||
|
|
||||||
|
class FollowerHandler(webapp.RequestHandler):
|
||||||
|
|
||||||
|
@decorator.oauth_required
|
||||||
|
def get(self):
|
||||||
|
try:
|
||||||
|
http = decorator.http()
|
||||||
|
followers = service.people().list(
|
||||||
|
userId='@me', groupId='@followers').execute(http)
|
||||||
|
text = 'Hello, you have %s followers!' % followers['totalResults']
|
||||||
|
|
||||||
|
path = os.path.join(os.path.dirname(__file__), 'welcome.html')
|
||||||
|
self.response.out.write(template.render(path, {'text': text }))
|
||||||
|
except AccessTokenRefreshError:
|
||||||
|
self.redirect('/')
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
application = webapp.WSGIApplication(
|
||||||
|
[
|
||||||
|
('/', MainHandler),
|
||||||
|
('/followers', FollowerHandler),
|
||||||
|
],
|
||||||
|
debug=True)
|
||||||
|
run_wsgi_app(application)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
1
samples/appengine_with_decorator2/oauth2
Symbolic link
1
samples/appengine_with_decorator2/oauth2
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../appengine/oauth2
|
||||||
1
samples/appengine_with_decorator2/oauth2client
Symbolic link
1
samples/appengine_with_decorator2/oauth2client
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../oauth2client/
|
||||||
1
samples/appengine_with_decorator2/uritemplate
Symbolic link
1
samples/appengine_with_decorator2/uritemplate
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../appengine/uritemplate
|
||||||
8
samples/appengine_with_decorator2/welcome.html
Normal file
8
samples/appengine_with_decorator2/welcome.html
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Welcome</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>{{ text }}</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user