Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
expose ADAL_SSL_NO_VERIFY to skip cert verification (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
yugangw-msft authored Jul 27, 2016
1 parent 9b98487 commit 4b92529
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
### Installation

``` $ pip install adal ```

### http tracing/proxy
If need to bypass self-signed certificates, turn on the environment variable of `ADAL_PYTHON_SSL_NO_VERIFY`
8 changes: 6 additions & 2 deletions adal/authentication_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# THE SOFTWARE.
#
#------------------------------------------------------------------------------

import os
import threading

from .authority import Authority
Expand Down Expand Up @@ -66,7 +66,11 @@ def __init__(self, authority, validate_authority=None, cache=None):
self.authority = Authority(authority, validate_authority is None or validate_authority)
self._oauth2client = None
self.correlation_id = None
self._call_context = {'options': GLOBAL_ADAL_OPTIONS}
env_value = os.environ.get('ADAL_PYTHON_SSL_NO_VERIFY')
self._call_context = {
'options': GLOBAL_ADAL_OPTIONS,
'verify_ssl': None if env_value is None else not env_value # mainly for tracing through proxy
}
self._token_requests_with_user_code = {}
self.cache = cache or TokenCache()
self._lock = threading.RLock()
Expand Down
3 changes: 2 additions & 1 deletion adal/authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def _perform_dynamic_instance_discovery(self):
self._log.debug("Attempting instance discover at: %s", discovery_endpoint.geturl())

try:
resp = requests.get(discovery_endpoint.geturl(), headers=get_options['headers'])
resp = requests.get(discovery_endpoint.geturl(), headers=get_options['headers'],
verify=self._call_context.get('verify_ssl', None))
util.log_return_correlation_id(self._log, operation, resp)
except Exception:
self._log.info("%s request failed", operation)
Expand Down
3 changes: 2 additions & 1 deletion adal/mex.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def discover(self):

try:
operation = "Mex Get"
resp = requests.get(self._url, headers=options['headers'])
resp = requests.get(self._url, headers=options['headers'],
verify=self._call_context.get('verify_ssl', None))
util.log_return_correlation_id(self._log, operation, resp)
except Exception:
self._log.info("%s request failed", operation)
Expand Down
9 changes: 6 additions & 3 deletions adal/oauth2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ def get_token(self, oauth_parameters):
try:
resp = requests.post(token_url.geturl(),
data=url_encoded_token_request,
headers=post_options['headers'])
headers=post_options['headers'],
verify=self._call_context.get('verify_ssl', None))

util.log_return_correlation_id(self._log, operation, resp)
except Exception:
Expand Down Expand Up @@ -285,7 +286,8 @@ def get_user_code_info(self, oauth_parameters):
try:
resp = requests.post(device_code_url.geturl(),
data=url_encoded_code_request,
headers=post_options['headers'])
headers=post_options['headers'],
verify=self._call_context.get('verify_ssl', None))
util.log_return_correlation_id(self._log, operation, resp)
except Exception:
self._log.info("%s request failed", operation)
Expand Down Expand Up @@ -320,7 +322,8 @@ def get_token_with_polling(self, oauth_parameters, refresh_internal, expires_in)

resp = requests.post(
token_url.geturl(),
data=url_encoded_code_request, headers=post_options['headers'])
data=url_encoded_code_request, headers=post_options['headers'],
verify=self._call_context.get('verify_ssl', None))

util.log_return_correlation_id(self._log, operation, resp)

Expand Down
3 changes: 2 additions & 1 deletion adal/user_realm.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def discover(self):
user_realm_url.geturl())

operation = 'User Realm Discovery'
resp = requests.get(user_realm_url.geturl(), headers=options['headers'])
resp = requests.get(user_realm_url.geturl(), headers=options['headers'],
verify=self._call_context.get('verify_ssl', None))
util.log_return_correlation_id(self._log, operation, resp)

if not util.is_http_success(resp.status_code):
Expand Down
3 changes: 2 additions & 1 deletion adal/wstrust_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def acquire_token(self, username, password):
self._log.debug("Sending RST to: %s", self._wstrust_endpoint_url)

operation = "WS-Trust RST"
resp = requests.post(self._wstrust_endpoint_url, headers=options['headers'], data=rst, allow_redirects=True)
resp = requests.post(self._wstrust_endpoint_url, headers=options['headers'], data=rst,
allow_redirects=True, verify=self._call_context.get('verify_ssl', None))

util.log_return_correlation_id(self._log, operation, resp)

Expand Down

0 comments on commit 4b92529

Please sign in to comment.