Python tornado.httputil.url_concat() Examples
The following are 30
code examples of tornado.httputil.url_concat().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tornado.httputil
, or try the search function
.
Example #1
Source File: auth.py From opendevops with GNU General Public License v3.0 | 6 votes |
def _oauth_request_token_url( self, redirect_uri: str = None, client_id: str = None, client_secret: str = None, code: str = None, extra_params: Dict[str, Any] = None, ) -> str: url = self._OAUTH_ACCESS_TOKEN_URL # type: ignore args = {} # type: Dict[str, str] if redirect_uri is not None: args["redirect_uri"] = redirect_uri if code is not None: args["code"] = code if client_id is not None: args["client_id"] = client_id if client_secret is not None: args["client_secret"] = client_secret if extra_params: args.update(extra_params) return url_concat(url, args)
Example #2
Source File: auth.py From honeything with GNU General Public License v3.0 | 6 votes |
def authorize_redirect(self, redirect_uri=None, client_id=None, client_secret=None, extra_params=None): """Redirects the user to obtain OAuth authorization for this service. Some providers require that you register a Callback URL with your application. You should call this method to log the user in, and then call get_authenticated_user() in the handler you registered as your Callback URL to complete the authorization process. """ args = { "redirect_uri": redirect_uri, "client_id": client_id } if extra_params: args.update(extra_params) self.redirect( url_concat(self._OAUTH_AUTHORIZE_URL, args))
Example #3
Source File: auth.py From teleport with Apache License 2.0 | 6 votes |
def _oauth_request_token_url( self, redirect_uri: str = None, client_id: str = None, client_secret: str = None, code: str = None, extra_params: Dict[str, Any] = None, ) -> str: url = self._OAUTH_ACCESS_TOKEN_URL # type: ignore args = {} # type: Dict[str, str] if redirect_uri is not None: args["redirect_uri"] = redirect_uri if code is not None: args["code"] = code if client_id is not None: args["client_id"] = client_id if client_secret is not None: args["client_secret"] = client_secret if extra_params: args.update(extra_params) return url_concat(url, args)
Example #4
Source File: handlers.py From nativeauthenticator with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _render(self, login_error=None, username=None): self._register_template_path() return self.render_template( 'native-login.html', next=url_escape(self.get_argument('next', default='')), username=username, login_error=login_error, custom_html=self.authenticator.custom_html, login_url=self.settings['login_url'], enable_signup=self.authenticator.enable_signup, two_factor_auth=self.authenticator.allow_2fa, authenticator_login_url=url_concat( self.authenticator.login_url(self.hub.base_url), {'next': self.get_argument('next', '')}, ), )
Example #5
Source File: auth.py From teleport with Apache License 2.0 | 6 votes |
def _oauth_request_token_url( self, redirect_uri: str = None, client_id: str = None, client_secret: str = None, code: str = None, extra_params: Dict[str, Any] = None, ) -> str: url = self._OAUTH_ACCESS_TOKEN_URL # type: ignore args = {} # type: Dict[str, str] if redirect_uri is not None: args["redirect_uri"] = redirect_uri if code is not None: args["code"] = code if client_id is not None: args["client_id"] = client_id if client_secret is not None: args["client_secret"] = client_secret if extra_params: args.update(extra_params) return url_concat(url, args)
Example #6
Source File: okpy.py From oauthenticator with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_auth_request(self, code): params = dict( redirect_uri=self.oauth_callback_url, code=code, grant_type='authorization_code', ) b64key = a2b_base64("{}:{}".format(self.client_id, self.client_secret)).decode( 'ascii' ) url = url_concat(self.token_url, params) req = HTTPRequest( url, method="POST", headers={ "Accept": "application/json", "User-Agent": "JupyterHub", "Authorization": "Basic {}".format(b64key), }, body='', # Body is required for a POST... ) return req
Example #7
Source File: bitbucket.py From oauthenticator with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _check_team_whitelist(self, username, access_token): http_client = AsyncHTTPClient() headers = _api_headers(access_token) # We verify the team membership by calling teams endpoint. next_page = url_concat( "https://api.bitbucket.org/2.0/teams", {'role': 'member'} ) while next_page: req = HTTPRequest(next_page, method="GET", headers=headers) resp = await http_client.fetch(req) resp_json = json.loads(resp.body.decode('utf8', 'replace')) next_page = resp_json.get('next', None) user_teams = set([entry["username"] for entry in resp_json["values"]]) # check if any of the organizations seen thus far are in whitelist if len(self.bitbucket_team_whitelist & user_teams) > 0: return True return False
Example #8
Source File: authenticator.py From everware with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _check_group_whitelist(self, username, headers): http_client = AsyncHTTPClient() # We verify the team membership by calling teams endpoint. # Re-use the headers, change the request. next_page = url_concat("https://api.bitbucket.org/2.0/teams", {'role': 'member'}) user_teams = set() while next_page: req = HTTPRequest(next_page, method="GET", headers=headers) resp = yield http_client.fetch(req) resp_json = json.loads(resp.body.decode('utf8', 'replace')) next_page = resp_json.get('next', None) user_teams |= \ set([entry["username"] for entry in resp_json["values"]]) return len(self.team_whitelist & user_teams) > 0
Example #9
Source File: home_handler.py From everware with BSD 3-Clause "New" or "Revised" License | 6 votes |
def commit_container(request, spawner, log): image_tag = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') image_name = 'everware_image/' + spawner.escaped_name + '/' + spawner.escaped_repo_url + '_' + spawner.container_id host_with_protocol = request.protocol + '://' + request.host url_with_image = url_concat(host_with_protocol + '/hub/spawn', dict(repourl='docker:' + image_name + ':' + image_tag)) log.info('Will commit %s' % url_with_image) commit = yield spawner.docker( 'commit', container=spawner.container_id, repository=image_name, tag=image_tag, message='Commit from control panel', author=spawner.escaped_name ) output_data = dict() if commit: output_data['url_with_image'] = url_with_image else: output_data['message'] = 'Sorry, can not save container' return output_data
Example #10
Source File: test_build.py From binderhub with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_build(app, needs_build, needs_launch, always_build, slug, pytestconfig): # can't use mark.github_api since only some tests here use GitHub if slug.startswith('gh/') and "not github_api" in pytestconfig.getoption('markexpr'): pytest.skip("Skipping GitHub API test") build_url = f"{app.url}/build/{slug}" r = await async_requests.get(build_url, stream=True) r.raise_for_status() events = [] async for line in async_requests.iter_lines(r): line = line.decode('utf8', 'replace') if line.startswith('data:'): event = json.loads(line.split(':', 1)[1]) events.append(event) assert 'message' in event sys.stdout.write(event['message']) final = events[-1] assert 'phase' in final assert final['phase'] == 'ready' assert 'url' in final assert 'token' in final print(final['url']) r = await async_requests.get(url_concat(final['url'], {'token': final['token']})) r.raise_for_status() assert r.url.startswith(final['url'])
Example #11
Source File: auth_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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)))
Example #12
Source File: httputil_test.py From honeything with GNU General Public License v3.0 | 5 votes |
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")
Example #13
Source File: httputil_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def test_url_concat_q_with_no_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")
Example #14
Source File: auth.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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)
Example #15
Source File: auth.py From pySINDy with MIT License | 5 votes |
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)
Example #16
Source File: httputil_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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")
Example #17
Source File: httputil_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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")
Example #18
Source File: httputil_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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")
Example #19
Source File: httputil_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def test_url_concat_no_params(self): url = url_concat( "https://localhost/path?r=1&t=2", [], ) self.assertEqual(url, "https://localhost/path?r=1&t=2")
Example #20
Source File: auth.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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()
Example #21
Source File: auth.py From honeything with GNU General Public License v3.0 | 5 votes |
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)
Example #22
Source File: auth_test.py From pySINDy with MIT License | 5 votes |
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)))
Example #23
Source File: auth_test.py From teleport with Apache License 2.0 | 5 votes |
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)))
Example #24
Source File: auth.py From pySINDy with MIT License | 5 votes |
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`. .. deprecated:: 5.1 The ``callback`` argument and returned awaitable will be removed in Tornado 6.0; this will be an ordinary synchronous function. """ 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()
Example #25
Source File: web.py From pySINDy with MIT License | 5 votes |
def get(self, *args): to_url = self._url.format(*args) if self.request.query_arguments: to_url = httputil.url_concat( to_url, list(httputil.qs_to_qsl(self.request.query_arguments))) self.redirect(to_url, permanent=self._permanent)
Example #26
Source File: okpy.py From oauthenticator with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_user_info_request(self, access_token): headers = { "Accept": "application/json", "User-Agent": "JupyterHub", "Authorization": "Bearer {}".format(access_token), } params = {"envelope": "false"} url = url_concat(self.userdata_url, params) req = HTTPRequest(url, method="GET", headers=headers) return req
Example #27
Source File: auth.py From teleport with Apache License 2.0 | 5 votes |
def authorize_redirect( self, redirect_uri: str = None, client_id: str = None, client_secret: str = None, extra_params: Dict[str, Any] = None, scope: str = None, response_type: str = "code", ) -> None: """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:: 6.0 The ``callback`` argument and returned awaitable were removed; this is now an ordinary synchronous function. """ handler = cast(RequestHandler, self) args = {"response_type": response_type} if redirect_uri is not None: args["redirect_uri"] = redirect_uri if client_id is not None: args["client_id"] = client_id if extra_params: args.update(extra_params) if scope: args["scope"] = " ".join(scope) url = self._OAUTH_AUTHORIZE_URL # type: ignore handler.redirect(url_concat(url, args))
Example #28
Source File: web.py From teleport with Apache License 2.0 | 5 votes |
def get(self, *args: Any) -> None: to_url = self._url.format(*args) if self.request.query_arguments: # TODO: figure out typing for the next line. to_url = httputil.url_concat( to_url, list(httputil.qs_to_qsl(self.request.query_arguments)), # type: ignore ) self.redirect(to_url, permanent=self._permanent)
Example #29
Source File: auth.py From tornado-zh with MIT License | 5 votes |
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()
Example #30
Source File: web.py From teleport with Apache License 2.0 | 5 votes |
def get(self, *args: Any) -> None: to_url = self._url.format(*args) if self.request.query_arguments: # TODO: figure out typing for the next line. to_url = httputil.url_concat( to_url, list(httputil.qs_to_qsl(self.request.query_arguments)), # type: ignore ) self.redirect(to_url, permanent=self._permanent)