AzureAD/microsoft-authentication-extensions-for-python

KeyChainError while authenticating using MSAL in from Mac OS

anilpuvvadi opened this issue · 1 comments

I work for Microsoft for Project Bonsai(AI & Research) team. I get the below error on my mac, when I try to run "bonsai brain create" command. We use msal package.

virtualenv) apuvvadiworkmacs-MacBook-Pro:brain apuvvadi$ bonsai brain create -n aniltest
No access token found in cache, please sign in.
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code FTHHCMWHX to authenticate.
Traceback (most recent call last):
File "/Users/apuvvadi/work/virtualenv/bin/bonsai", line 33, in
sys.exit(load_entry_point('bonsai-cli', 'console_scripts', 'bonsai')())
File "/Users/apuvvadi/brain/src/Services/bonsaicli2/bonsai_cli/commands/bonsai.py", line 278, in main
cli()
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/apuvvadi/brain/src/Services/bonsaicli2/bonsai_cli/commands/brain.py", line 72, in create_brain
response = api(use_aad=True).create_brain(
File "/Users/apuvvadi/brain/src/Services/bonsaicli2/bonsai_cli/utils.py", line 32, in api
bonsai_config = Config(argv=sys.argv, use_aad=use_aad)
File "/Users/apuvvadi/brain/src/Services/bonsaicli2/bonsai_cli/config.py", line 127, in init
self.accesskey = self.aad_client.get_access_token()
File "/Users/apuvvadi/brain/src/Services/bonsaicli2/bonsai_cli/aad.py", line 129, in get_access_token
self._log_in_with_device_code()
File "/Users/apuvvadi/brain/src/Services/bonsaicli2/bonsai_cli/aad.py", line 95, in _log_in_with_device_code
return self._app.acquire_token_by_device_flow(flow)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal/application.py", line 902, in acquire_token_by_device_flow
return self.client.obtain_token_by_device_flow(
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal/oauth2cli/oauth2.py", line 348, in obtain_token_by_device_flow
result = self._obtain_token_by_device_flow(flow, **kwargs)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal/oauth2cli/oauth2.py", line 310, in _obtain_token_by_device_flow
result = self._obtain_token(
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal/oauth2cli/oidc.py", line 89, in _obtain_token
ret = super(Client, self)._obtain_token(grant_type, *args, **kwargs)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal/oauth2cli/oauth2.py", line 485, in _obtain_token
(on_obtaining_tokens or self.on_obtaining_tokens)({
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal/application.py", line 298, in
on_obtaining_tokens=lambda event: self.token_cache.add(dict(
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal/token_cache.py", line 290, in add
super(SerializableTokenCache, self).add(event, **kwargs)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal/token_cache.py", line 113, in add
return self.__add(event, now=now)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal/token_cache.py", line 173, in __add
self.modify(self.CredentialType.ACCESS_TOKEN, at, at)
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal_extensions/token_cache.py", line 49, in modify
self._persistence.save(self.serialize())
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal_extensions/persistence.py", line 208, in save
locker.set_generic_password(
File "/Users/apuvvadi/work/virtualenv/lib/python3.8/site-packages/msal_extensions/osx.py", line 216, in set_generic_password
raise KeychainError(exit_status=modify_exit_status)

Based on the error code -67030 , The solution suggested in the link provided by Abhidnya Patil jaraco/keyring#219 (comment) worked. This issue can be closed.