From: Ben Darnell Date: Sun, 18 Mar 2018 21:07:42 +0000 (-0400) Subject: auth: Deprecated _oauth_get_user X-Git-Tag: v5.1.0b1~38^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a0714e7357a7b6cde74b8b1af0d27dfba3e6391;p=thirdparty%2Ftornado.git auth: Deprecated _oauth_get_user --- diff --git a/tornado/auth.py b/tornado/auth.py index c9cec8d91..12cf37d89 100644 --- a/tornado/auth.py +++ b/tornado/auth.py @@ -527,7 +527,14 @@ class OAuthMixin(object): For backwards compatibility, the callback-based ``_oauth_get_user`` method is also supported. + + .. deprecated:: 5.1 + + The ``_oauth_get_user`` fallback is deprecated and support for it + will be removed in 6.0. """ + warnings.warn("_oauth_get_user is deprecated, override _oauth_get_user_future instead", + DeprecationWarning) # By default, call the old-style _oauth_get_user, but new code # should override this method instead. self._oauth_get_user(access_token, callback) diff --git a/tornado/test/auth_test.py b/tornado/test/auth_test.py index 1652dca2c..704ab6c06 100644 --- a/tornado/test/auth_test.py +++ b/tornado/test/auth_test.py @@ -18,6 +18,7 @@ from tornado import gen from tornado.httputil import url_concat from tornado.log import gen_log from tornado.testing import AsyncHTTPTestCase, ExpectLog +from tornado.test.util import ignore_deprecation from tornado.web import RequestHandler, Application, asynchronous, HTTPError @@ -121,12 +122,13 @@ class OAuth1ClientLoginHandler(RequestHandler, OAuthMixin): return yield self.authorize_redirect(http_client=self.settings['http_client']) - def _oauth_get_user(self, access_token, callback): + @gen.coroutine + def _oauth_get_user_future(self, access_token): if self.get_argument('fail_in_get_user', None): raise Exception("failing in get_user") if access_token != dict(key='uiop', secret='5678'): raise Exception("incorrect access token %r" % access_token) - callback(dict(email='foo@example.com')) + return dict(email='foo@example.com') class OAuth1ClientLoginCoroutineHandler(OAuth1ClientLoginHandler): @@ -465,9 +467,10 @@ class AuthTest(AsyncHTTPTestCase): response.headers['Set-Cookie']) def test_oauth10_get_user_legacy(self): - response = self.fetch( - '/legacy/oauth10/client/login?oauth_token=zxcv', - headers={'Cookie': '_oauth_request_token=enhjdg==|MTIzNA=='}) + with ignore_deprecation(): + response = self.fetch( + '/legacy/oauth10/client/login?oauth_token=zxcv', + headers={'Cookie': '_oauth_request_token=enhjdg==|MTIzNA=='}) response.rethrow() parsed = json_decode(response.body) self.assertEqual(parsed['email'], 'foo@example.com') @@ -502,9 +505,10 @@ class AuthTest(AsyncHTTPTestCase): response.headers['Set-Cookie']) def test_oauth10a_get_user_legacy(self): - response = self.fetch( - '/legacy/oauth10a/client/login?oauth_token=zxcv', - headers={'Cookie': '_oauth_request_token=enhjdg==|MTIzNA=='}) + with ignore_deprecation(): + response = self.fetch( + '/legacy/oauth10a/client/login?oauth_token=zxcv', + headers={'Cookie': '_oauth_request_token=enhjdg==|MTIzNA=='}) response.rethrow() parsed = json_decode(response.body) self.assertEqual(parsed['email'], 'foo@example.com')