Freigeben über


VisualStudioCodeCredential Class

Authenticates as the Azure user signed in to Visual Studio Code via the 'Azure Account' extension.

It's a known issue that this credential doesn't work with Azure Account extension versions newer than 0.9.11. A long-term fix to this problem is in progress. In the meantime, consider authenticating with AzureCliCredential.

Constructor

VisualStudioCodeCredential(**kwargs: Any)

Keyword-Only Parameters

Name Description
authority
str

Authority of a Microsoft Entra endpoint, for example "login.microsoftonline.com". This argument is required for a custom cloud and usually unnecessary otherwise. Defaults to the authority matching the "Azure: Cloud" setting in VS Code's user settings or, when that setting has no value, the authority for Azure Public Cloud.

tenant_id
str

ID of the tenant the credential should authenticate in. Defaults to the "Azure: Tenant" setting in VS Code's user settings or, when that setting has no value, the "organizations" tenant, which supports only Microsoft Entra work or school accounts.

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.

Methods

close

Close the credential's transport session.

get_token

Request an access token for scopes as the user currently signed in to Visual Studio Code.

This method is called automatically by Azure SDK clients.

get_token_info

Request an access token for scopes as the user currently signed in to Visual Studio Code.

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.

close

Close the credential's transport session.

close() -> None

get_token

Request an access token for scopes as the user currently signed in to Visual Studio Code.

This method is called automatically by Azure SDK clients.

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

Parameters

Name Description
scopes
Required
str

desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.

Keyword-Only Parameters

Name Description
claims
str

additional claims required in the token, such as those returned in a resource provider's claims challenge following an authorization failure.

Default value: None
tenant_id
str

optional tenant to include in the token request.

Default value: None

Returns

Type Description

An access token with the desired scopes.

Exceptions

Type Description

the credential cannot retrieve user details from Visual Studio Code

get_token_info

Request an access token for scopes as the user currently signed in to Visual Studio Code.

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.

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

Parameters

Name Description
scopes
Required
str

desired scopes for the access token. This method requires at least one scope. For more information about scopes, see https://learn.microsoft.com/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.

Default value: None

Returns

Type Description

An AccessTokenInfo instance containing information about the token.

Exceptions

Type Description

the credential cannot retrieve user details from Visual Studio Code.