AcquireTokenOptions.ManagedIdentity Property

Definition

When ManagedIdentity is set, the application uses a managed identity instead of client credentials to acquire an app token. To use a system-assigned identity, simply leave UserAssignedClientId null. To use a user-assigned identity, set UserAssignedClientId to the ClientID of the user-assigned identity you want to use. Using either form of managed identity requires the application to be deployed on Azure and the managed identity to be configured. For more details, check the managed identities for Azure documentation.

public Microsoft.Identity.Abstractions.ManagedIdentityOptions? ManagedIdentity { get; set; }
member this.ManagedIdentity : Microsoft.Identity.Abstractions.ManagedIdentityOptions with get, set
Public Property ManagedIdentity As ManagedIdentityOptions

Property Value

Examples

The Json fragment below describes how to use a system-assigned Managed Identity for authentication in a confidential client application :

The code below describes the same, programmatically in C#.

The Json fragment below describes how to use a user-assigned Managed Identity for authentication in a confidential client application :

{
    "AquireTokenOptions": {
        "ManagedIdentity": {
            "UserAssignedClientId": "[ClientIdForTheManagedIdentityResource]"
        }
    }
}

The code below describes the same, programmatically in C#.

ManagedIdentityOptions managedIdentityOptions = new ManagedIdentityOptions
{
    UserAssignedClientId = "[ClientIdForTheManagedIdentityResource]"
};

AcquireTokenOptions acquireTokenOptions = new AcquireTokenOptions
{
    ManagedIdentity = managedIdentityOptions
};

Applies to