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
Cleaning None values
  • Loading branch information
abhidnya13 committed Mar 23, 2020
commit cb70a37cb99f4ffbe3b0958cda0a2a9f689e013c
6 changes: 5 additions & 1 deletion msal/oauth2cli/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ def _obtain_token( # The verb "obtain" is influenced by OAUTH2 RFC 6749

_data.update(self.default_body) # It may contain authen parameters
_data.update(data or {}) # So the content in data param prevails
# We don't have to clean up None values here, because requests lib will.
filtered = {k: v for k, v in _data.items() if v is not None}
_data.clear()
_data.update(filtered)
# We will have to clean up None values here,
# because we can have some libraries not supporting cleaning of None values.

if _data.get('scope'):
_data['scope'] = self._stringify(_data['scope'])
Expand Down
49 changes: 49 additions & 0 deletions sample/httpx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import httpx

from .oauth2cli import HttpClient, Response


class DefaultHttpClient(HttpClient):
"""
Default HTTP Client
"""
def __init__(self):
"""
Constructor for the DefaultHttpClient
verify=True, # type: Union[str, True, False, None]
proxies=None, # type: Optional[dict]
"""
self.session = httpx.Client()

def post(self, url, params=None, data=None, headers=None, **kwargs):
if params is None:
params = {}
params.update(**kwargs)

response = self.session.post(url=url, params=params, headers=headers, data=data)
return Response(response.status_code, response.text, response)

def get(self, url, params=None, headers=None, **kwargs):
if params is None:
params = {}
params.update(kwargs)
response = self.session.get(url=url, params=params, headers=headers)
return Response(response.status_code, response.text, response)


class Response(Response):

def __init__(self, status_code, text, response):
"""Constructor for DefaultResponseObject
status, # type: int
text, # type: str response in string format
response, # type: Raw response from requests
"""
self.status_code = status_code
self.text = text
self.response = response


def raise_for_status(self):
self.response.raise_for_status()
48 changes: 48 additions & 0 deletions sample/httpx_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import httpx
from httpx import *
from msal.oauth2cli import HttpClient, Response


class HttpxClient(HttpClient):
"""
Default HTTP Client
"""
def __init__(self):
"""
Constructor for the DefaultHttpClient
verify=True, # type: Union[str, True, False, None]
proxies=None, # type: Optional[dict]
"""

def post(self, url, params=None, data=None, headers=None, **kwargs):
if params is None:
params = {}
params.update(**kwargs)

response = httpx.post(url=url, params=params, headers=headers, data=data)
return Response(response.status_code, response.text, response)

def get(self, url, params=None, headers=None, **kwargs):
if params is None:
params = {}
params.update(kwargs)
response = httpx.get(url=url, params=params, headers=headers)
return Response(response.status_code, response.text, response)


class Response(Response):

def __init__(self, status_code, text, response):
"""Constructor for DefaultResponseObject
status, # type: int
text, # type: str response in string format
response, # type: Raw response from requests
"""
self.status_code = status_code
self.text = text
self.response = response


def raise_for_status(self):
self.response.raise_for_status()