Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow refreshing the token obtained by InteractiveBrowserCredential #10278

Closed
superhrusha opened this issue Mar 12, 2020 · 8 comments · Fixed by #10612
Closed

Allow refreshing the token obtained by InteractiveBrowserCredential #10278

superhrusha opened this issue Mar 12, 2020 · 8 comments · Fixed by #10612
Assignees
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved.
Milestone

Comments

@superhrusha
Copy link

The problem I am trying to solve:

  • I am writing a desktop client app that will programmatically connect to Azure storages
  • The app will be run by multiple stakeholders in the organization from their personal computers
  • The storages contain sensitive information so I want to properly secure access- access should be based on AD, much like Azure CLI works.
  • I have a working solution but the token I get expires in one hour.
  • I want to provide a good UX. Requiring the user to interactively authenticate once an hour is unacceptable.
  • As far as I know the standard way to deal with theses situations is by using the refresh token
  • unfortunately, the refresh token is discarded by the InteractiveBrowserCredential.get_token method.

The solution I'd like
I would like the mechanism to allow me to refresh an expired token without bothering the user of the app.

Alternative I considered
override the get_token method and try to implement it myself by extracting relevant code. It would be hacky

@chlowell chlowell added Azure.Identity customer-reported Issues that are reported by GitHub users external to the Azure organization. Client This issue points to a problem in the data-plane of the library. and removed triage labels Mar 12, 2020
@chlowell
Copy link
Member

Hi @superhrusha, thanks for opening this. We're working on improvements to caching (tracked by #9744) and user authentication that will enable the solution you'd like in an upcoming release. I'll use this issue to track work around giving applications more control over how and when InteractiveBrowserCredential and other user credentials authenticate.

@chlowell chlowell self-assigned this Mar 12, 2020
@superhrusha
Copy link
Author

superhrusha commented Mar 13, 2020 via email

@chlowell
Copy link
Member

User auth changes will roll out in beta releases over the next few months. I'll update this issue when something's available for feedback.

@superhrusha
Copy link
Author

@chlowell, any chance you can recommend a workaround or a temporary solution, however hacky it maybe?
e.g - suppose I can get hold of the refresh token. How would I use it with the existing API?

@chlowell
Copy link
Member

The public API never returns or accepts a refresh token, and we don't intend to change that. Any workaround involving getting or using one would therefore rely on private APIs which will soon change.

After rereading this issue I wonder whether I've misunderstood the problem. InteractiveBrowserCredential doesn't discard refresh tokens. If Azure AD provided one at the initial authentication, InteractiveBrowserCredential should redeem it when an access token expires. The token cache here is in-memory though, so all is lost when the process exits. Are you looking for a way to persist authentication across executions of your program, or have you observed multiple authentication prompts during a single execution?

@superhrusha
Copy link
Author

superhrusha commented Mar 23, 2020

The latter - persist across executions. I am looking to provide an experience similar to how Azure CLI works.
It persists the access token and the refresh token in a local file. This way it can be used across executions.

@chlowell
Copy link
Member

Then we're on the same page. That persistence is the work in progress I mentioned above. If you need to implement your own persistence today, the best way is to write your own credential (the interface is simple).

If your users happen to be signed in to the CLI, there might be a workaround for you there. In the current beta of azure-identity (1.4.0b1) DefaultAzureCredential can use the Azure CLI's authenticated identity.

@chlowell chlowell added this to the [2020] May milestone Mar 24, 2020
@chlowell chlowell added the feature-request This issue requires a new behavior in the product in order be resolved. label Apr 21, 2020
@chlowell
Copy link
Member

chlowell commented May 4, 2020

In azure-identity 1.4.0b3, released today, InteractiveBrowserCredential will silently refresh tokens as needed. Please open an issue if you encounter any problems using it.

Today's release also includes optional caching to disk on Windows when the credential is constructed with enable_persistent_cache=True. We'll add persistent caching on Linux and macOS in a future release (that work is tracked by #11134).

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants