Skip to content

Conversation

@abhidnya13
Copy link
Contributor

@abhidnya13 abhidnya13 commented Apr 24, 2020


UPDATED: Quoted a bug report from Jørgen Steffensen:

Hi,

First of all thank you for providing this great addition to the MSAL library, it is a very useful library.

I tried the latest release (msal-extensions 0.2.1) and get the following error when using the device token flow on Windows 10 (version 0.1.3 of msal-extensions works fine).

------ CMD output start ------------------------------------------------------------------------------------------------------------------------------------

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ………. to authenticate.

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

…

    result = Client.__app.acquire_token_by_device_flow(flow)  # By default it will block
  File " testenv\venv\lib\site-packages\msal\application.py", line 724, in acquire_token_by_device_flow
    **kwargs)
  File "testenv\venv\lib\site-packages\msal\oauth2cli\oauth2.py", line 280, in obtain_token_by_device_flow
    result = self._obtain_token_by_device_flow(flow, **kwargs)
  File "testenv\venv\lib\site-packages\msal\oauth2cli\oauth2.py", line 243, in _obtain_token_by_device_flow
    self.DEVICE_FLOW["GRANT_TYPE"], data=data, **kwargs)
  File "testenv\venv\lib\site-packages\msal\oauth2cli\oidc.py", line 83, in _obtain_token
    ret = super(Client, self)._obtain_token(grant_type, *args, **kwargs)
  File "testenv\venv\lib\site-packages\msal\oauth2cli\oauth2.py", line 419, in _obtain_token
    "response": _resp, "params": params, "data": _data,
  File "testenv\venv\lib\site-packages\msal\token_cache.py", line 288, in add
    super(SerializableTokenCache, self).add(event, **kwargs)
  File "testenv\venv\lib\site-packages\msal\token_cache.py", line 113, in add
    return self.__add(event, now=now)
  File "testenv\venv\lib\site-packages\msal\token_cache.py", line 171, in __add
    self.modify(self.CredentialType.ACCESS_TOKEN, at, at)
  File "testenv\venv\lib\site-packages\msal_extensions\token_cache.py", line 50, in modify
    self._persistence.save(self.serialize())
  File "testenv\venv\lib\site-packages\msal_extensions\persistence.py", line 118, in save
    self._dp_agent.protect(content))
  File "testenv\venv\lib\site-packages\msal_extensions\persistence.py", line 85, in save
    handle.write(content)
TypeError: write() argument must be str, not bytes
------ CMD output end ------------------------------------------------------------------------------------------------------------------------------------

@abhidnya13 abhidnya13 requested a review from rayluo April 24, 2020 22:54
Comment on lines 121 to 123
with open(self._location, 'rb') as handle:
return self._dp_agent.unprotect(
handle.read())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
with open(self._location, 'rb') as handle:
return self._dp_agent.unprotect(
handle.read())
# type: () -> str
with open(self._location, 'rb') as handle:
return self._dp_agent.unprotect(handle.read())

Given that we are getting into the nasty difference of string and bytes anyway, let's also include a type hint here. Same suggestion for save() too. In the near future (but not in this PR), we will pick up another task for documentation, and describe this in details there.

Also, since this is not automated, please manually test this test case and that sample, on both Python 2.7 and one version of Python 3, we need to see all pass in such 2x2 matrix. Please ack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Manually tested the test case and the sample on Python 2.7 and 3.7 and it works fine

Copy link
Contributor

@rayluo rayluo left a comment

Choose a reason for hiding this comment

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

Ship it!

@abhidnya13 abhidnya13 merged commit b91d36a into dev Apr 25, 2020
@abhidnya13 abhidnya13 deleted the persistence_test branch April 25, 2020 01:44
@abhidnya13 abhidnya13 mentioned this pull request Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants