Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added oauth2 login using proxy setting #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 28 additions & 14 deletions authomatic/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"""

import abc
import os
import authomatic.core
import base64
import hashlib
import logging
Expand Down Expand Up @@ -399,24 +401,36 @@ def _fetch(self, url, method='GET', params=None, headers=None,
headers.update(
{'Content-Type': 'application/x-www-form-urlencoded'})
request_path = parse.urlunsplit(('', '', path or '', query or '', ''))

self._log(logging.DEBUG, u' \u251C\u2500 host: {0}'.format(host))
self._log(
logging.DEBUG,
u' \u251C\u2500 path: {0}'.format(request_path))
self._log(logging.DEBUG, u' \u251C\u2500 method: {0}'.format(method))
self._log(logging.DEBUG, u' \u251C\u2500 body: {0}'.format(body))
self._log(logging.DEBUG, u' \u251C\u2500 params: {0}'.format(params))
self._log(logging.DEBUG, u' \u2514\u2500 headers: {0}'.format(headers))


self._log(logging.DEBUG, ' \u251C\u2500 host: {0}'.format(host))
self._log(logging.DEBUG, ' \u251C\u2500 path: {0}'.format(request_path))
self._log(logging.DEBUG, ' \u251C\u2500 method: {0}'.format(method))
self._log(logging.DEBUG, ' \u251C\u2500 body: {0}'.format(body))
self._log(logging.DEBUG, ' \u251C\u2500 params: {0}'.format(params))
self._log(logging.DEBUG, ' \u2514\u2500 headers: {0}'.format(headers))

http_proxy = os.environ.get('http_proxy')
https_proxy = os.environ.get('https_proxy')
type_,https_host = https_proxy.split('//')
type_,http_host = http_proxy.split('//')
# Connect
if scheme.lower() == 'https':
connection = http_client.HTTPSConnection(host)
else:
connection = http_client.HTTPConnection(host)
if https_proxy is not None:
connection = http_client.HTTPSConnection(https_host)
connection.set_tunnel(host)
else:
connection = http_client.HTTPSConnection(host)

elif scheme.lower() == 'http':
if http_proxy is not None:
connection = http_client.HTTPConnection(http_host)
connection.set_tunnel(host)
else:
connection = http_client.HTTPConnection(host)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY - this can be written simpler.



try:
connection.request(method, request_path, body, headers)
connection.request(method, url, body, headers)
except Exception as e:
raise FetchError('Fetching URL failed',
original_message=str(e),
Expand Down