diff --git a/samples/appengine_with_decorator/apiclient b/samples/appengine_with_decorator/apiclient new file mode 120000 index 0000000..24fe0bc --- /dev/null +++ b/samples/appengine_with_decorator/apiclient @@ -0,0 +1 @@ +../appengine/apiclient \ No newline at end of file diff --git a/samples/appengine_with_decorator/app.yaml b/samples/appengine_with_decorator/app.yaml new file mode 100644 index 0000000..c0d43d5 --- /dev/null +++ b/samples/appengine_with_decorator/app.yaml @@ -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 + diff --git a/samples/appengine_with_decorator/better.py b/samples/appengine_with_decorator/better.py new file mode 100644 index 0000000..03963f4 --- /dev/null +++ b/samples/appengine_with_decorator/better.py @@ -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 + +""" + +__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 +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() diff --git a/samples/appengine_with_decorator/gflags.py b/samples/appengine_with_decorator/gflags.py new file mode 120000 index 0000000..5a2ff94 --- /dev/null +++ b/samples/appengine_with_decorator/gflags.py @@ -0,0 +1 @@ +../../gflags.py \ No newline at end of file diff --git a/samples/appengine_with_decorator/gflags_validators.py b/samples/appengine_with_decorator/gflags_validators.py new file mode 120000 index 0000000..25d8ce8 --- /dev/null +++ b/samples/appengine_with_decorator/gflags_validators.py @@ -0,0 +1 @@ +../../gflags_validators.py \ No newline at end of file diff --git a/samples/appengine_with_decorator/httplib2 b/samples/appengine_with_decorator/httplib2 new file mode 120000 index 0000000..4cd2774 --- /dev/null +++ b/samples/appengine_with_decorator/httplib2 @@ -0,0 +1 @@ +../appengine/httplib2 \ No newline at end of file diff --git a/samples/appengine_with_decorator/index.yaml b/samples/appengine_with_decorator/index.yaml new file mode 100644 index 0000000..a3b9e05 --- /dev/null +++ b/samples/appengine_with_decorator/index.yaml @@ -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. diff --git a/samples/appengine_with_decorator/main.py b/samples/appengine_with_decorator/main.py new file mode 100755 index 0000000..ca08d29 --- /dev/null +++ b/samples/appengine_with_decorator/main.py @@ -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 + +""" + +__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 +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() diff --git a/samples/appengine_with_decorator/oauth2 b/samples/appengine_with_decorator/oauth2 new file mode 120000 index 0000000..ee61c25 --- /dev/null +++ b/samples/appengine_with_decorator/oauth2 @@ -0,0 +1 @@ +../appengine/oauth2 \ No newline at end of file diff --git a/samples/appengine_with_decorator/oauth2client b/samples/appengine_with_decorator/oauth2client new file mode 120000 index 0000000..9013119 --- /dev/null +++ b/samples/appengine_with_decorator/oauth2client @@ -0,0 +1 @@ +../../oauth2client/ \ No newline at end of file diff --git a/samples/appengine_with_decorator/uritemplate b/samples/appengine_with_decorator/uritemplate new file mode 120000 index 0000000..1c98e41 --- /dev/null +++ b/samples/appengine_with_decorator/uritemplate @@ -0,0 +1 @@ +../appengine/uritemplate \ No newline at end of file diff --git a/samples/appengine_with_decorator2/apiclient b/samples/appengine_with_decorator2/apiclient new file mode 120000 index 0000000..24fe0bc --- /dev/null +++ b/samples/appengine_with_decorator2/apiclient @@ -0,0 +1 @@ +../appengine/apiclient \ No newline at end of file diff --git a/samples/appengine_with_decorator2/app.yaml b/samples/appengine_with_decorator2/app.yaml new file mode 100644 index 0000000..c0d43d5 --- /dev/null +++ b/samples/appengine_with_decorator2/app.yaml @@ -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 + diff --git a/samples/appengine_with_decorator2/gflags.py b/samples/appengine_with_decorator2/gflags.py new file mode 120000 index 0000000..5a2ff94 --- /dev/null +++ b/samples/appengine_with_decorator2/gflags.py @@ -0,0 +1 @@ +../../gflags.py \ No newline at end of file diff --git a/samples/appengine_with_decorator2/gflags_validators.py b/samples/appengine_with_decorator2/gflags_validators.py new file mode 120000 index 0000000..25d8ce8 --- /dev/null +++ b/samples/appengine_with_decorator2/gflags_validators.py @@ -0,0 +1 @@ +../../gflags_validators.py \ No newline at end of file diff --git a/samples/appengine_with_decorator2/grant.html b/samples/appengine_with_decorator2/grant.html new file mode 100644 index 0000000..a52ea08 --- /dev/null +++ b/samples/appengine_with_decorator2/grant.html @@ -0,0 +1,17 @@ + + + Can Haz Perms? + + + {% if has_credentials %} +

Thanks for granting us permission. Please proceed to the main + application.

+ {% else %} +

Grant this application permission to read your + Buzz information and it will let you know how many followers you have.

+ {% endif %} +

You can always revoke + permission at any time.

+ + diff --git a/samples/appengine_with_decorator2/httplib2 b/samples/appengine_with_decorator2/httplib2 new file mode 120000 index 0000000..4cd2774 --- /dev/null +++ b/samples/appengine_with_decorator2/httplib2 @@ -0,0 +1 @@ +../appengine/httplib2 \ No newline at end of file diff --git a/samples/appengine_with_decorator2/index.yaml b/samples/appengine_with_decorator2/index.yaml new file mode 100644 index 0000000..a3b9e05 --- /dev/null +++ b/samples/appengine_with_decorator2/index.yaml @@ -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. diff --git a/samples/appengine_with_decorator2/main.py b/samples/appengine_with_decorator2/main.py new file mode 100644 index 0000000..03963f4 --- /dev/null +++ b/samples/appengine_with_decorator2/main.py @@ -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 + +""" + +__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 +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() diff --git a/samples/appengine_with_decorator2/oauth2 b/samples/appengine_with_decorator2/oauth2 new file mode 120000 index 0000000..ee61c25 --- /dev/null +++ b/samples/appengine_with_decorator2/oauth2 @@ -0,0 +1 @@ +../appengine/oauth2 \ No newline at end of file diff --git a/samples/appengine_with_decorator2/oauth2client b/samples/appengine_with_decorator2/oauth2client new file mode 120000 index 0000000..9013119 --- /dev/null +++ b/samples/appengine_with_decorator2/oauth2client @@ -0,0 +1 @@ +../../oauth2client/ \ No newline at end of file diff --git a/samples/appengine_with_decorator2/uritemplate b/samples/appengine_with_decorator2/uritemplate new file mode 120000 index 0000000..1c98e41 --- /dev/null +++ b/samples/appengine_with_decorator2/uritemplate @@ -0,0 +1 @@ +../appengine/uritemplate \ No newline at end of file diff --git a/samples/appengine_with_decorator2/welcome.html b/samples/appengine_with_decorator2/welcome.html new file mode 100644 index 0000000..57b186e --- /dev/null +++ b/samples/appengine_with_decorator2/welcome.html @@ -0,0 +1,8 @@ + + + Welcome + + +

{{ text }}

+ +