Remove user_agent from app engine helpers.
This commit is contained in:
@@ -71,7 +71,7 @@ class AppAssertionCredentials(AssertionCredentials):
|
||||
AssertionFlowCredentials objects may be safely pickled and unpickled.
|
||||
"""
|
||||
|
||||
def __init__(self, scope, user_agent,
|
||||
def __init__(self, scope,
|
||||
audience='https://accounts.google.com/o/oauth2/token',
|
||||
assertion_type='http://oauth.net/grant_type/jwt/1.0/bearer',
|
||||
token_uri='https://accounts.google.com/o/oauth2/token', **kwargs):
|
||||
@@ -79,7 +79,6 @@ class AppAssertionCredentials(AssertionCredentials):
|
||||
|
||||
Args:
|
||||
scope: string, scope of the credentials being requested.
|
||||
user_agent: string, The HTTP User-Agent to provide for this application.
|
||||
audience: string, The audience, or verifier of the assertion. For
|
||||
convenience defaults to Google's audience.
|
||||
assertion_type: string, Type name that will identify the format of the
|
||||
@@ -94,7 +93,7 @@ class AppAssertionCredentials(AssertionCredentials):
|
||||
|
||||
super(AppAssertionCredentials, self).__init__(
|
||||
assertion_type,
|
||||
user_agent,
|
||||
None,
|
||||
token_uri)
|
||||
|
||||
def _generate_assertion(self):
|
||||
@@ -261,8 +260,7 @@ class OAuth2Decorator(object):
|
||||
decorator = OAuth2Decorator(
|
||||
client_id='837...ent.com',
|
||||
client_secret='Qh...wwI',
|
||||
scope='https://www.googleapis.com/auth/buzz',
|
||||
user_agent='my-sample-app/1.0')
|
||||
scope='https://www.googleapis.com/auth/buzz')
|
||||
|
||||
|
||||
class MainHandler(webapp.RequestHandler):
|
||||
@@ -275,7 +273,7 @@ class OAuth2Decorator(object):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, client_id, client_secret, scope, user_agent,
|
||||
def __init__(self, client_id, client_secret, scope,
|
||||
auth_uri='https://accounts.google.com/o/oauth2/auth',
|
||||
token_uri='https://accounts.google.com/o/oauth2/token'):
|
||||
|
||||
@@ -285,14 +283,13 @@ class OAuth2Decorator(object):
|
||||
client_id: string, client identifier.
|
||||
client_secret: string client secret.
|
||||
scope: string, scope of the credentials being requested.
|
||||
user_agent: string, HTTP User-Agent to provide for this application.
|
||||
auth_uri: string, URI for authorization endpoint. For convenience
|
||||
defaults to Google's endpoints but any OAuth 2.0 provider can be used.
|
||||
token_uri: string, URI for token endpoint. For convenience
|
||||
defaults to Google's endpoints but any OAuth 2.0 provider can be used.
|
||||
"""
|
||||
self.flow = OAuth2WebServerFlow(client_id, client_secret, scope,
|
||||
user_agent, auth_uri, token_uri)
|
||||
self.flow = OAuth2WebServerFlow(client_id, client_secret, scope, None,
|
||||
auth_uri, token_uri)
|
||||
self.credentials = None
|
||||
self._request_handler = None
|
||||
|
||||
|
||||
@@ -202,9 +202,12 @@ class OAuth2Credentials(Credentials):
|
||||
"""Generate the headers that will be used in the refresh request
|
||||
"""
|
||||
headers = {
|
||||
'user-agent': self.user_agent,
|
||||
'content-type': 'application/x-www-form-urlencoded',
|
||||
}
|
||||
|
||||
if self.user_agent is not None:
|
||||
headers['user-agent'] = self.user_agent
|
||||
|
||||
return headers
|
||||
|
||||
def _refresh(self, http_request):
|
||||
@@ -289,10 +292,12 @@ class OAuth2Credentials(Credentials):
|
||||
if headers == None:
|
||||
headers = {}
|
||||
headers['authorization'] = 'OAuth ' + self.access_token
|
||||
if 'user-agent' in headers:
|
||||
headers['user-agent'] = self.user_agent + ' ' + headers['user-agent']
|
||||
else:
|
||||
headers['user-agent'] = self.user_agent
|
||||
|
||||
if self.user_agent is not None:
|
||||
if 'user-agent' in headers:
|
||||
headers['user-agent'] = self.user_agent + ' ' + headers['user-agent']
|
||||
else:
|
||||
headers['user-agent'] = self.user_agent
|
||||
|
||||
resp, content = request_orig(uri, method, body, headers,
|
||||
redirections, connection_type)
|
||||
@@ -494,9 +499,12 @@ class OAuth2WebServerFlow(Flow):
|
||||
'scope': self.scope,
|
||||
})
|
||||
headers = {
|
||||
'user-agent': self.user_agent,
|
||||
'content-type': 'application/x-www-form-urlencoded',
|
||||
}
|
||||
|
||||
if self.user_agent is not None:
|
||||
headers['user-agent'] = self.user_agent
|
||||
|
||||
if http is None:
|
||||
http = httplib2.Http()
|
||||
resp, content = http.request(self.token_uri, method='POST', body=body,
|
||||
|
||||
@@ -40,8 +40,7 @@ from google.appengine.ext.webapp.util import run_wsgi_app
|
||||
from oauth2client.appengine import AppAssertionCredentials
|
||||
|
||||
credentials = AppAssertionCredentials(
|
||||
scope='https://www.googleapis.com/auth/urlshortener',
|
||||
user_agent='my-sample-app/1.0')
|
||||
scope='https://www.googleapis.com/auth/urlshortener')
|
||||
|
||||
http = credentials.authorize(httplib2.Http(memcache))
|
||||
service = build("urlshortener", "v1", http=http)
|
||||
|
||||
@@ -93,9 +93,7 @@ class TestAppAssertionCredentials(unittest.TestCase):
|
||||
app_identity_stub)
|
||||
|
||||
self.scope = "http://www.googleapis.com/scope"
|
||||
user_agent = "hal/3.0"
|
||||
|
||||
self.credentials = AppAssertionCredentials(self.scope, user_agent)
|
||||
self.credentials = AppAssertionCredentials(self.scope)
|
||||
|
||||
def test_assertion(self):
|
||||
assertion = self.credentials._generate_assertion()
|
||||
@@ -133,8 +131,7 @@ class DecoratorTests(unittest.TestCase):
|
||||
|
||||
decorator = OAuth2Decorator(client_id='foo_client_id',
|
||||
client_secret='foo_client_secret',
|
||||
scope='foo_scope',
|
||||
user_agent='foo_user_agent')
|
||||
scope='foo_scope')
|
||||
self.decorator = decorator
|
||||
|
||||
class TestRequiredHandler(webapp.RequestHandler):
|
||||
|
||||
Reference in New Issue
Block a user