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
Removing default http client
  • Loading branch information
abhidnya13 committed Mar 30, 2020
commit 293b081810f9dc52516e2e06e446aa2e670a7129
10 changes: 8 additions & 2 deletions msal/application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import requests
import time
try: # Python 2
from urlparse import urljoin
Expand All @@ -9,7 +10,7 @@
import warnings
import uuid

from .oauth2cli import Client, JwtAssertionCreator, DefaultHttpClient
from .oauth2cli import Client, JwtAssertionCreator
from .authority import Authority
from .mex import send_request as mex_send_request
from .wstrust_request import send_request as wst_send_request
Expand Down Expand Up @@ -162,7 +163,12 @@ def __init__(
self.client_id = client_id
self.client_credential = client_credential
self.client_claims = client_claims
self.http_client = http_client if http_client else DefaultHttpClient(verify=verify, proxies=proxies)
if http_client:
self.http_client = http_client
else:
self.http_client = requests.Session()
self.http_client.verify = verify
self.http_client.proxies = proxies
self.timeout = timeout
self.app_name = app_name
self.app_version = app_version
Expand Down
1 change: 0 additions & 1 deletion msal/oauth2cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
from .assertion import JwtAssertionCreator
from .assertion import JwtSigner # Obsolete. For backward compatibility.
from .http import HttpClient
from .default_http_client import DefaultHttpClient
28 changes: 0 additions & 28 deletions msal/oauth2cli/default_http_client.py

This file was deleted.

10 changes: 4 additions & 6 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
from mock import * # Need an external mock package

from msal.application import *
from msal.oauth2cli.default_http_client import Response
import msal
from tests import unittest
from tests.test_token_cache import TokenCacheTestCase

import requests

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
Expand Down Expand Up @@ -47,9 +46,8 @@ def test_extract_multiple_tag_enclosed_certs(self):
class TestClientApplicationAcquireTokenSilentErrorBehaviors(unittest.TestCase):

def setUp(self):
self.http_client = DefaultHttpClient()
self.authority_url = "https://login.microsoftonline.com/common"
self.authority = msal.authority.Authority(self.authority_url, http_client= self.http_client)
self.authority = msal.authority.Authority(self.authority_url, http_client= requests.Session())
self.scopes = ["s1", "s2"]
self.uid = "my_uid"
self.utid = "my_utid"
Expand All @@ -66,7 +64,7 @@ def setUp(self):
uid=self.uid, utid=self.utid, refresh_token=self.rt),
}) # The add(...) helper populates correct home_account_id for future searching
self.app = ClientApplication(
self.client_id, authority=self.authority_url, token_cache=self.cache, http_client=self.http_client)
self.client_id, authority=self.authority_url, token_cache=self.cache)

def test_cache_empty_will_be_returned_as_None(self):
self.assertEqual(
Expand Down Expand Up @@ -108,7 +106,7 @@ class TestClientApplicationAcquireTokenSilentFociBehaviors(unittest.TestCase):

def setUp(self):
self.authority_url = "https://login.microsoftonline.com/common"
self.authority = msal.authority.Authority(self.authority_url, DefaultHttpClient())
self.authority = msal.authority.Authority(self.authority_url, requests.Session())
self.scopes = ["s1", "s2"]
self.uid = "my_uid"
self.utid = "my_utid"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from msal.authority import *
from tests import unittest
from msal.oauth2cli.default_http_client import DefaultHttpClient
import requests


@unittest.skipIf(os.getenv("TRAVIS_TAG"), "Skip network io during tagged release")
Expand All @@ -11,7 +11,7 @@ class TestAuthority(unittest.TestCase):
def test_wellknown_host_and_tenant(self):
# Assert all well known authority hosts are using their own "common" tenant
for host in WELL_KNOWN_AUTHORITY_HOSTS:
a = Authority('https://{}/common'.format(host), DefaultHttpClient())
a = Authority('https://{}/common'.format(host), requests.Session())
self.assertEqual(
a.authorization_endpoint,
'https://%s/common/oauth2/v2.0/authorize' % host)
Expand All @@ -24,14 +24,14 @@ def test_lessknown_host_will_return_a_set_of_v1_endpoints(self):
# It is probably not a strict API contract. I simply mention it here.
less_known = 'login.windows.net' # less.known.host/
v1_token_endpoint = 'https://{}/common/oauth2/token'.format(less_known)
a = Authority('https://{}/common'.format(less_known), DefaultHttpClient())
a = Authority('https://{}/common'.format(less_known), requests.Session())
self.assertEqual(a.token_endpoint, v1_token_endpoint)
self.assertNotIn('v2.0', a.token_endpoint)

def test_unknown_host_wont_pass_instance_discovery(self):
_assert = getattr(self, "assertRaisesRegex", self.assertRaisesRegexp) # Hack
with _assert(ValueError, "invalid_instance"):
Authority('https://example.com/tenant_doesnt_matter_in_this_case', DefaultHttpClient())
Authority('https://example.com/tenant_doesnt_matter_in_this_case', requests.Session())

def test_invalid_host_skipping_validation_can_be_turned_off(self):
try:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from msal.oauth2cli import Client, JwtSigner
from msal.oauth2cli.authcode import obtain_auth_code
from msal.oauth2cli.default_http_client import DefaultHttpClient
from tests import unittest, Oauth2TestCase


Expand Down Expand Up @@ -100,13 +99,13 @@ def setUpClass(cls):
issuer=CONFIG["client_id"],
),
client_assertion_type=Client.CLIENT_ASSERTION_TYPE_JWT,
http_client=DefaultHttpClient()
http_client=requests.Session()
)
else:
cls.client = Client(
CONFIG["openid_configuration"], CONFIG['client_id'],
client_secret=CONFIG.get('client_secret'),
http_client=DefaultHttpClient())
http_client=requests.Session())

@unittest.skipIf(
"token_endpoint" not in CONFIG.get("openid_configuration", {}),
Expand Down