From 57a214f7df8ec4c8eaca0c74056d6cf1f6b7497b Mon Sep 17 00:00:00 2001 From: MiCHiLU Date: Sun, 22 Dec 2013 18:18:35 +0700 Subject: [PATCH] use ndb --- simpleauth/handler.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/simpleauth/handler.py b/simpleauth/handler.py index 722ded1..c9a598c 100644 --- a/simpleauth/handler.py +++ b/simpleauth/handler.py @@ -27,6 +27,7 @@ # users module is needed for OpenID authentication. from google.appengine.api import urlfetch, users +from google.appengine.ext import ndb from webapp2_extras import security __all__ = ['SimpleAuthHandler', @@ -195,6 +196,7 @@ def _oauth2_init(self, provider, auth_url): self.redirect(target_url) + @ndb.synctasklet def _oauth2_callback(self, provider, access_token_url): """Step 2 of OAuth 2.0, whenever the user accepts or denies access.""" error = self.request.get('error') @@ -221,7 +223,7 @@ def _oauth2_callback(self, provider, access_token_url): 'grant_type': 'authorization_code' } - resp = urlfetch.fetch( + resp = yield ndb.get_context().urlfetch( url=access_token_url, payload=urlencode(payload), method=urlfetch.POST, @@ -233,7 +235,7 @@ def _oauth2_callback(self, provider, access_token_url): auth_info = _parser(resp.content) user_data = _fetcher(auth_info, key=client_id, secret=client_secret) - return (user_data, auth_info) + raise ndb.Return((user_data, auth_info)) def _oauth1_init(self, provider, auth_urls): """Initiates OAuth 1.0 dance""" @@ -489,12 +491,14 @@ def _oauth1_client(self, token=None, consumer_key=None, return oauth1.Client(*args) + @ndb.synctasklet def _oauth2_request(self, url, token, token_param='access_token'): """Makes an HTTP request with OAuth 2.0 access token using App Engine URLfetch API. """ target_url = url.format(urlencode({token_param:token})) - return urlfetch.fetch(target_url).content + resp = yield ndb.get_context().urlfetch(target_url) + raise ndb.Return(resp.content) def _query_string_parser(self, body): """Parses response body of an access token request query and returns