InteractiveBrowserCredential
azure.identity.InteractiveBrowserCredential with a persisted cache and get_refresh_token().
Usage
InteractiveBrowserCredential(
*,
allow_unencrypted_storage=False,
**kwargs,
)It also signs in through a callback page, as httr2 does. With no redirect_uri or a localhost one, the parent’s local listener and system browser sign in. Any other redirect_uri (a page the user’s browser can load, such as a code-server URL) prints MSAL’s authorize URL and reads back what the callback page shows: the callback URL, base64 JSON with code and state, or the code and then the state, as httr2::req_oauth_auth_code() does. That needs an interactive session. Caching is as DeviceCodeCredential.
Parameters
allow_unencrypted_storage: bool = False-
Fall back to a plain file where the platform’s secret store is unusable, as for DeviceCodeCredential.
**kwargs: Any-
Passed to
azure.identity.InteractiveBrowserCredential:tenant_id,client_id,redirect_uri,login_hint,authority,authentication_recordand the rest. Aredirect_uriwhose host is notlocalhostor127.0.0.1is kept by dazapiz for the pasted-code flow and not passed on.
Raises
ValueError-
allow_unencrypted_storage=Truetogether withcache_persistence_options, or (from the parent) a localhostredirect_uriwithout a port.
Notes
Everything but the cache default, get_refresh_token() and the pasted-code flow is azure-identity’s. The pasted-code flow uses the parent’s MSAL app: initiate_auth_code_flow() builds the PKCE pair, state and nonce, and acquire_token_by_auth_code_flow() checks the state and redeems the code, so the tokens land in the same cache. Signing in raises azure.identity.CredentialUnavailableError in a session that is not interactive (no TTY, no notebook kernel), and azure.core.exceptions.ClientAuthenticationError for a pasted reply with an error, no code, no state, or a state that does not match. The app registration must list the redirect URI as a public client (“Mobile and desktop applications”), since no client secret is sent.
Examples
from dazapiz import InteractiveBrowserCredential
credential = InteractiveBrowserCredential(
tenant_id="11111111-2222-3333-4444-555555555555",
client_id="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
redirect_uri="https://your-domain.example/azure-callback",
)
token = credential.get_token("User.Read").token # prompts once, then silentMethods
| Name | Description |
|---|---|
| get_refresh_token() | The signed-in user’s refresh token, signing in first if nobody has. |
get_refresh_token()
The signed-in user’s refresh token, signing in first if nobody has.
Usage
get_refresh_token()Calls authenticate() when the credential has no AuthenticationRecord yet, then reads the token from the persisted cache azure-identity wrote, with the record’s client ID, tenant and username.
Returns
RefreshTokenInfo- The newest refresh token in the cache for the signed-in account.
Raises
RefreshTokenNotFoundError- The persisted cache holds no refresh token for the account, or cannot be read.
Notes
The cache is opened with the same msal_extensions persistence azure-identity uses for its cache_persistence_options, and only loaded: nothing is written or copied. This reads azure-identity’s private _persistent_cache layout, which its public API does not expose.