Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions simpleauth/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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')
Expand All @@ -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,
Expand All @@ -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"""
Expand Down Expand Up @@ -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
Expand Down