AzurePowerShellCredential Class

Authenticates by requesting a token from Azure PowerShell.

This requires previously logging in to Azure via "Connect-AzAccount", and will use the currently logged in identity.

Inheritance
builtins.object
AzurePowerShellCredential

Constructor

AzurePowerShellCredential(*, tenant_id: str = '', additionally_allowed_tenants: List[str] | None = None, process_timeout: int = 10)

Keyword-Only Parameters

Name Description
tenant_id
str

Optional tenant to include in the token request.

additionally_allowed_tenants

Specifies tenants in addition to the specified "tenant_id" for which the credential may acquire tokens. Add the wildcard value "*" to allow the credential to acquire tokens for any tenant the application can access.

process_timeout
int

Seconds to wait for the Azure PowerShell process to respond. Defaults to 10 seconds.

Default value: 10

Examples

Create an AzurePowerShellCredential.


   from azure.identity import AzurePowerShellCredential

   credential = AzurePowerShellCredential()

Methods

close

Calling this method is unnecessary.

get_token

Request an access token for scopes.

This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesn't cache the tokens it acquires.

get_token_info

Request an access token for scopes.

This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesn't cache the tokens it acquires.

close

Calling this method is unnecessary.

close() -> None

get_token

Request an access token for scopes.

This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesn't cache the tokens it acquires.

get_token(*scopes: str, claims: str | None = None, tenant_id: str | None = None, **kwargs: Any) -> AccessToken

Parameters

Name Description
scopes
Required
str

desired scope for the access token. This credential allows only one scope per request. For more information about scopes, see https://zcusa.951200.xyz/entra/identity-platform/scopes-oidc.

Keyword-Only Parameters

Name Description
claims
str

not used by this credential; any value provided will be ignored.

tenant_id
str

optional tenant to include in the token request.

Returns

Type Description

An access token with the desired scopes.

Exceptions

Type Description

the credential was unable to invoke Azure PowerShell, or no account is authenticated

the credential invoked Azure PowerShell but didn't receive an access token

get_token_info

Request an access token for scopes.

This is an alternative to get_token to enable certain scenarios that require additional properties on the token. This method is called automatically by Azure SDK clients. Applications calling this method directly must also handle token caching because this credential doesn't cache the tokens it acquires.

get_token_info(*scopes: str, options: TokenRequestOptions | None = None) -> AccessTokenInfo

Parameters

Name Description
scopes
Required
str

desired scopes for the access token. TThis credential allows only one scope per request. For more information about scopes, see https://zcusa.951200.xyz/entra/identity-platform/scopes-oidc.

Keyword-Only Parameters

Name Description
options

A dictionary of options for the token request. Unknown options will be ignored. Optional.

Returns

Type Description
<xref:AccessTokenInfo>

An AccessTokenInfo instance containing information about the token.

Exceptions

Type Description

the credential was unable to invoke Azure PowerShell, or no account is authenticated

the credential invoked Azure PowerShell but didn't receive an access token