Skip to content

Commit

Permalink
Adding support for user assigned managed identity (#1008)
Browse files Browse the repository at this point in the history
proposed fix for #1007
* Adding support for user assigned managed identity
* Update src/Microsoft.Identity.Web/CertificateManagement/DefaultCertificateLoader.cs
Co-authored-by: jennyf19 <jeferrie@microsoft.com>
  • Loading branch information
jmprieur authored Mar 4, 2021
1 parent 93839ab commit 8a3bebc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ namespace Microsoft.Identity.Web
/// </summary>
public class DefaultCertificateLoader : ICertificateLoader
{
/// <summary>
/// User assigned managed identity client ID (as opposed to system assigned managed identity)
/// See https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-manage-ua-identity-portal.
/// </summary>
public static string? UserAssignedManagedIdentityClientId { get; set; }

/// <summary>
/// Load the certificate from the description, if needed.
/// </summary>
Expand Down Expand Up @@ -102,7 +108,9 @@ private static X509Certificate2 LoadFromKeyVault(
X509KeyStorageFlags x509KeyStorageFlags)
{
Uri keyVaultUri = new Uri(keyVaultUrl);
DefaultAzureCredential credential = new DefaultAzureCredential();
DefaultAzureCredentialOptions options = new DefaultAzureCredentialOptions();
options.ManagedIdentityClientId = UserAssignedManagedIdentityClientId;
DefaultAzureCredential credential = new DefaultAzureCredential(options);
CertificateClient certificateClient = new CertificateClient(keyVaultUri, credential);
SecretClient secretClient = new SecretClient(keyVaultUri, credential);

Expand Down
12 changes: 12 additions & 0 deletions src/Microsoft.Identity.Web/Microsoft.Identity.Web.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Microsoft.Identity.Web/MicrosoftIdentityOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,11 @@ internal bool HasClientCredentials
/// </summary>
/// The default is <c>false.</c>
public bool AllowWebApiToBeAuthorizedByACL { get; set; }

/// <summary>
/// Used, when deployed to Azure, to specify explicitly a user assigned managed identity.
/// See https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-manage-ua-identity-portal.
/// </summary>
public string? UserAssignedManagedIdentityClientId { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Microsoft.Identity.Web/TokenAcquisition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public TokenAcquisition(
_applicationOptions.ClientSecret ??= _microsoftIdentityOptions.ClientSecret;
_applicationOptions.TenantId ??= _microsoftIdentityOptions.TenantId;
_applicationOptions.LegacyCacheCompatibilityEnabled = _microsoftIdentityOptions.LegacyCacheCompatibilityEnabled;
DefaultCertificateLoader.UserAssignedManagedIdentityClientId = _microsoftIdentityOptions.UserAssignedManagedIdentityClientId;
}

/// <summary>
Expand Down

0 comments on commit 8a3bebc

Please # to comment.