Esempio n. 1
0
    def authorize_redirect(self,
                           redirect_uri=None,
                           client_id=None,
                           client_secret=None,
                           extra_params=None,
                           callback=None,
                           scope=None,
                           response_type="code"):
        """Redirects the user to obtain OAuth authorization for this service.

        Some providers require that you register a redirect URL with
        your application instead of passing one via this method. You
        should call this method to log the user in, and then call
        ``get_authenticated_user`` in the handler for your
        redirect URL to complete the authorization process.

        .. versionchanged:: 3.1
           Returns a `.Future` and takes an optional callback.  These are
           not strictly necessary as this method is synchronous,
           but they are supplied for consistency with
           `OAuthMixin.authorize_redirect`.
        """
        args = {
            "redirect_uri": redirect_uri,
            "client_id": client_id,
            "response_type": response_type
        }
        if extra_params:
            args.update(extra_params)
        if scope:
            args['scope'] = ' '.join(scope)
        self.redirect(url_concat(self._OAUTH_AUTHORIZE_URL, args))
        callback()
Esempio n. 2
0
 def _oauth_request_token_url(self,
                              redirect_uri=None,
                              client_id=None,
                              client_secret=None,
                              code=None,
                              extra_params=None):
     url = self._OAUTH_ACCESS_TOKEN_URL
     args = dict(
         redirect_uri=redirect_uri,
         code=code,
         client_id=client_id,
         client_secret=client_secret,
     )
     if extra_params:
         args.update(extra_params)
     return url_concat(url, args)
Esempio n. 3
0
 def test_url_concat_dict_params(self):
     url = url_concat(
         "https://localhost/path",
         dict(y='y'),
     )
     self.assertEqual(url, "https://localhost/path?y=y")
Esempio n. 4
0
 def test_url_concat_multi_same_params(self):
     url = url_concat(
         "https://localhost/path",
         [('y', 'y1'), ('y', 'y2')],
     )
     self.assertEqual(url, "https://localhost/path?y=y1&y=y2")
Esempio n. 5
0
 def test_url_concat_multi_same_query_params(self):
     url = url_concat(
         "https://localhost/path?r=1&r=2",
         [('y', 'y')],
     )
     self.assertEqual(url, "https://localhost/path?r=1&r=2&y=y")
Esempio n. 6
0
 def test_url_concat_none_params(self):
     url = url_concat(
         "https://localhost/path?r=1&t=2",
         None,
     )
     self.assertEqual(url, "https://localhost/path?r=1&t=2")
Esempio n. 7
0
 def test_url_concat_with_frag(self):
     url = url_concat(
         "https://localhost/path#tab",
         [('y', 'y')],
     )
     self.assertEqual(url, "https://localhost/path?y=y#tab")
Esempio n. 8
0
 def test_url_concat_mult_params(self):
     url = url_concat(
         "https://localhost/path?a=1&b=2",
         [('y', 'y'), ('z', 'z')],
     )
     self.assertEqual(url, "https://localhost/path?a=1&b=2&y=y&z=z")
Esempio n. 9
0
 def test_url_concat_trailing_amp(self):
     url = url_concat(
         "https://localhost/path?x&",
         [('y', 'y'), ('z', 'z')],
     )
     self.assertEqual(url, "https://localhost/path?x=&y=y&z=z")
Esempio n. 10
0
 def test_url_concat_encode_args(self):
     url = url_concat(
         "https://localhost/path",
         [('y', '/y'), ('z', 'z')],
     )
     self.assertEqual(url, "https://localhost/path?y=%2Fy&z=z")
Esempio n. 11
0
 def test_url_concat_no_query_params(self):
     url = url_concat(
         "https://localhost/path",
         [('y', 'y'), ('z', 'z')],
     )
     self.assertEqual(url, "https://localhost/path?y=y&z=z")
Esempio n. 12
0
 def get(self):
     # issue a fake auth code and redirect to redirect_uri
     code = 'fake-authorization-code'
     self.redirect(
         url_concat(self.get_argument('redirect_uri'), dict(code=code)))