Skip to content
Find file
executable file 62 lines (47 sloc) 1.97 KB
from google.appengine.ext import webapp, db
from django.utils import simplejson
from google.appengine.ext.webapp import util, template
from google.appengine.api import users
import urllib
from oauth.handlers import AuthorizationHandler, AccessTokenHandler
from oauth.models import OAuth_Client
from oauth.utils import oauth_required
# Notes:
# Access tokens usually live shorter than access grant
# Refresh tokens usually live as long as access grant
class MainHandler(webapp.RequestHandler):
def get(self):
self.response.out.write('Hello world!')
class ClientsHandler(webapp.RequestHandler):
""" This is only indirectly necessary since the spec
calls for clients, but managing them is out of scope """
def get(self):
clients = OAuth_Client.all()
template.render('templates/clients.html', locals()))
def post(self):
client = OAuth_Client(
name = self.request.get('name'),
redirect_uri = self.request.get('redirect_uri'), )
class ProtectedResourceHandler(webapp.RequestHandler):
""" This is an example of a resource protected by OAuth
and requires the 'read' scope """
SECRET_PAYLOAD = 'bananabread'
def get(self, token):
self.response.headers['Content-Type'] = "application/json"
simplejson.dumps({'is_protected': True, 'secret_payload': self.SECRET_PAYLOAD}))
def application():
return webapp.WSGIApplication([
('/', MainHandler),
('/oauth/authorize', AuthorizationHandler),
('/oauth/token', AccessTokenHandler),
('/protected/resource', ProtectedResourceHandler),
('/admin/clients', ClientsHandler), ],debug=True)
def main():
if __name__ == '__main__':
Jump to Line
Something went wrong with that request. Please try again.