]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
auth: Deprecated _oauth_get_user
authorBen Darnell <ben@bendarnell.com>
Sun, 18 Mar 2018 21:07:42 +0000 (17:07 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 18 Mar 2018 21:24:44 +0000 (17:24 -0400)
tornado/auth.py
tornado/test/auth_test.py

index c9cec8d91ee31d492d49b1ca7ca8db74c5b71b42..12cf37d896da2627c7b690d30f755375988784dc 100644 (file)
@@ -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)
index 1652dca2c169d410b37d25ec264eb27bca87add4..704ab6c0659814a13af91102a9f1df0d397f5eb3 100644 (file)
@@ -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')