microsoft / azure-quantum-python

The azure-quantum python package submits jobs to the Azure Quantum service.
https://learn.microsoft.com/azure/quantum/
MIT License
126 stars 92 forks source link

Add back the SharedTokenCacheCredential to handle token which is cached by the InteractiveBrowserCredential #603

Open ArthurKamalov opened 7 months ago

ArthurKamalov commented 7 months ago

The original problem: the InteractiveBrowserCredential required login by browser on each new run.

Observations: It seems that the InteractiveBrowserCredential is able to save its token to persistent cache storage, but it is not able to use that cache later. ( It actually has its own method _acquire_token_silent, but, as far as I can see, it does not check for token in cache, but already expects an instance of the AuthenticationRecord class, which, I assume, we have to handle and store manually) That's why I also made an assumtion that we should use SharedTokenCacheCredential for that. I know that the SharedTokenCacheCredential was previously removed by @vxfield and there might be a valid reason for that, but I haven't found any better workaround, so I would glad to hear whether we can use it or not.

vxfield commented 7 months ago

Observations: It seems that the InteractiveBrowserCredential is able to save its token to persistent cache storage, but it is not able to use that cache later. ( It actually has its own method _acquire_token_silent, but, as far as I can see, it does not check for token in cache, but already expects an instance of the AuthenticationRecord class, which, I assume, we have to handle and store manually) That's why I also made an assumtion that we should use SharedTokenCacheCredential for that. I know that the SharedTokenCacheCredential was previously removed by @vxfield and there might be a valid reason for that, but I haven't found any better workaround, so I would glad to hear whether we can use it or not.

The _auth_record is automatically set upon successful Browser Authentication source. We don't need to worry about it if we also use the SharedTokenCacheCredential as you said to use the cache on a different process or instantiation of our SDK.

vxfield commented 7 months ago

@ArthurKamalov, @kikomiss: I'll hand this back to you now.

I think the next steps would be to add test cases for the _DefaultAzureCredential.get_token() method with different authentication scenarios.

See how we instantiate the _DefaultAzureCredential here.

These new test cases: