Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cbe98f3
Initial commit
abhidnya13 Feb 25, 2020
e64332f
Iteration 1
abhidnya13 Mar 5, 2020
2a7d5e3
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 Mar 5, 2020
aed0e8d
Iteration 2 rectifying tests
abhidnya13 Mar 6, 2020
30f7d99
Iteration 3 modifying some more failing tests
abhidnya13 Mar 6, 2020
34e8e16
Iteration 4
abhidnya13 Mar 7, 2020
f60bbb5
Removing tests whose implementation was removed
abhidnya13 Mar 7, 2020
d54fb8b
Iteration 5
abhidnya13 Mar 7, 2020
be389d5
Replacing generic exception to specific Http error
abhidnya13 Mar 9, 2020
dcec4af
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 Mar 16, 2020
e37f0c3
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 Mar 16, 2020
b3a4e09
Refactor according to new interface
abhidnya13 Mar 20, 2020
96988f8
Changing one reference to new interface left in the previous one
abhidnya13 Mar 20, 2020
1d05615
Modified one more missed change
abhidnya13 Mar 20, 2020
ccafcf9
Few more changes and refactor
abhidnya13 Mar 20, 2020
2670e25
Adding raw response to response object
abhidnya13 Mar 20, 2020
cb70a37
Cleaning None values
abhidnya13 Mar 23, 2020
53520fd
PR review iteration
abhidnya13 Mar 26, 2020
293b081
Removing default http client
abhidnya13 Mar 30, 2020
fcac05e
cleaning up
abhidnya13 Mar 30, 2020
229ad26
Adding deleted single empty line back
abhidnya13 Mar 30, 2020
340210f
Updating filtering of non values from dictionary
abhidnya13 Mar 30, 2020
ca8a129
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 Apr 7, 2020
d993950
Capturing editorial changes
abhidnya13 Apr 13, 2020
e5ebd28
Review changes 1
abhidnya13 Apr 16, 2020
8901269
Fixing broken test
abhidnya13 Apr 16, 2020
7774be8
Cleaning up
abhidnya13 Apr 16, 2020
42ca7a2
PR review changes part 1
abhidnya13 Apr 17, 2020
d38d38d
PR review changes part 2
abhidnya13 Apr 17, 2020
3226bc4
PR review changes part 3
abhidnya13 Apr 17, 2020
90afb94
Minor indent change
abhidnya13 Apr 17, 2020
a1ce0d1
PR review changes part 4
abhidnya13 Apr 20, 2020
ad245a7
Adding back accidentally deleted blank line
abhidnya13 Apr 20, 2020
34bb127
Removing extra indent
abhidnya13 Apr 20, 2020
a745949
Minor line add in authority.py
abhidnya13 Apr 20, 2020
b636baa
Making changes for backward compatibility
abhidnya13 Apr 20, 2020
d24d575
Some more editorial changes
abhidnya13 Apr 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Iteration 1
  • Loading branch information
abhidnya13 committed Mar 5, 2020
commit e64332fca25bd16f39c65700700f134fb09ff7e9
11 changes: 2 additions & 9 deletions msal/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@ def __init__(
self.client_claims = client_claims
self.verify = verify
self.proxies = proxies
from msal.oauth2cli.http import DefaultHttpClient
self.http_client = http_client if http_client else DefaultHttpClient(self.verify, self.proxies)
self.http_client = http_client or DefaultHttpClient(verify=self.verify, proxy=self.proxies)
self.timeout = timeout
self.app_name = app_name
self.app_version = app_version
self.authority = Authority(
authority or "https://login.microsoftonline.com/common/",
validate_authority, verify=verify, proxies=proxies, timeout=timeout, http_client = self.http_client)
validate_authority, verify=verify, proxies=proxies, timeout=timeout, http_client=self.http_client)
# Here the self.authority is not the same type as authority in input
self.token_cache = token_cache or TokenCache()
self.client = self._build_client(client_credential, self.authority)
Expand Down Expand Up @@ -374,12 +373,6 @@ def _get_authority_aliases(self, instance):
resp = self.http_client.request("GET", "https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=https://login.microsoftonline.com/common/oauth2/authorize",
headers={'Accept': 'application/json'},
verify=self.verify, proxies=self.proxies, timeout=self.timeout)

# resp = requests.get(
# "https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=https://login.microsoftonline.com/common/oauth2/authorize",
# headers={'Accept': 'application/json'},
# verify=self.verify, proxies=self.proxies, timeout=self.timeout)
resp.raise_for_status()
self.authority_groups = [
set(group['aliases']) for group in resp.content.json()['metadata']]
for group in self.authority_groups:
Expand Down
15 changes: 2 additions & 13 deletions msal/authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from urlparse import urlparse
import logging

import requests

from .exceptions import MsalServiceError

Expand Down Expand Up @@ -54,7 +53,7 @@ def __init__(self, authority_url, validate_authority=True,
len(parts) == 3 and parts[2].lower().startswith("b2c_"))
if (tenant != "adfs" and (not is_b2c) and validate_authority
and self.instance not in WELL_KNOWN_AUTHORITY_HOSTS):
payload = instance_discovery(
payload = self.instance_discovery(
"https://{}{}/oauth2/v2.0/authorize".format(
self.instance, authority.path),
verify=verify, proxies=proxies, timeout=timeout)
Expand All @@ -74,7 +73,7 @@ def __init__(self, authority_url, validate_authority=True,
authority.path, # In B2C scenario, it is "/tenant/policy"
"" if tenant == "adfs" else "/v2.0" # the AAD v2 endpoint
))
openid_config = tenant_discovery(
openid_config = self.tenant_discovery(
tenant_discovery_endpoint,
verify=verify, proxies=proxies, timeout=timeout)
logger.debug("openid_config = %s", openid_config)
Expand All @@ -93,17 +92,7 @@ def user_realm_discovery(self, username, correlation_id=None, response=None):
netloc=self.instance, username=username), headers={'Accept':'application/json',
'client-request-id': correlation_id}, timeout= self.timeout)
if resp.status_code != 404:
resp.raise_for_status()
return resp.content.json()
# resp = response or requests.get(
# "https://{netloc}/common/userrealm/{username}?api-version=1.0".format(
# netloc=self.instance, username=username),
# headers={'Accept':'application/json',
# 'client-request-id': correlation_id},
# verify=self.verify, proxies=self.proxies, timeout=self.timeout)
# if resp.status_code != 404:
# resp.raise_for_status()
# return resp.json()
self.__class__._domains_without_user_realm_discovery.add(self.instance)
return {} # This can guide the caller to fall back normal ROPC flow

Expand Down
41 changes: 8 additions & 33 deletions msal/oauth2cli/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DefaultHttpClient(HttpClient):
"""
General purpose HTTP Client for interacting with the Twilio API
"""
def __init__(self, default_headers=None, verify=None, proxy=None):
def __init__(self, default_headers={}, verify=None, proxy=None):
"""
Constructor for the TwilioHttpClient

Expand All @@ -33,7 +33,6 @@ def __init__(self, default_headers=None, verify=None, proxy=None):
self.session.verify = verify
self.session.proxy = proxy


def request(self, method, url, params=None, data=None, headers=None, auth=None, timeout=None,
allow_redirects=False, **kwargs):
"""
Expand All @@ -50,37 +49,13 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None,
See the requests documentation for explanation of all these parameters

:return: An http response
:rtype: A :class:`Response <twilio.rest.http.response.Response>` object
:rtype: A :class:`Response <http.response.Response>` object
"""
# if timeout is not None and timeout <= 0:
# raise ValueError(timeout)
#
# kwargs = {
# 'method': method.upper(),
# 'url': url,
# 'params': params,
# 'data': data,
# 'headers': headers,
# 'auth': auth,
# 'hooks': self.request_hooks
# }
#
# if params:
# self.logger.info('{method} Request: {url}?{query}'.format(query=urlencode(params), **kwargs))
# self.logger.info('PARAMS: {params}'.format(**kwargs))
# else:
# self.logger.info('{method} Request: {url}'.format(**kwargs))
# if data:
# self.logger.info('PAYLOAD: {data}'.format(**kwargs))
#
# self.last_response = None
session = self.session or Session()
if method == "POST":
response = session.post(headers=headers, params=params, data=data, auth=auth,
timeout=timeout, **kwargs)
response = self.session.post(url=url, headers=headers, params=params, data=data, auth=auth,
timeout=timeout, **kwargs)
elif method == "GET":
response = requests.get(url= url, headers=headers, params=params, timeout=timeout)

self.last_response = Response(int(response.status_code), response.text)

return self.last_response
response = self.session.get(url=url, headers=headers, params=params, timeout=timeout, data=data, auth=auth)
response.raise_for_status()
response = Response(int(response.status_code), response)
return response
3 changes: 0 additions & 3 deletions msal/oauth2cli/http/http_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ def __init__(self, status_code, text):
@property
def text(self):
return self.content

def __repr__(self):
return 'HTTP {} {}'.format(self.status_code, self.content)
4 changes: 2 additions & 2 deletions msal/oauth2cli/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(
self.default_body["client_assertion_type"] = client_assertion_type
self.logger = logging.getLogger(__name__)
if not http_client:
self.http_client = DefaultHttpClient(verify, proxies or {})
self.http_client = DefaultHttpClient(verify=verify, proxy=proxies or {}, default_headers= {})
else:
self.http_client = http_client
self.timeout = timeout
Expand Down Expand Up @@ -150,7 +150,7 @@ def _obtain_token( # The verb "obtain" is influenced by OAUTH2 RFC 6749
raise ValueError("token_endpoint not found in configuration")
_headers = {'Accept': 'application/json'}
_headers.update(headers or {})
resp = (post or self.http_client.request)("POST", self.configuration["token_endpoint"],
resp = self.http_client.request("POST", self.configuration["token_endpoint"],
headers=_headers, params=params, data=_data, auth=auth,
timeout=timeout or self.timeout,
**kwargs)
Expand Down