Created
August 15, 2020 12:24
-
-
Save jarig/427f3be552e0e82e15521ea43d1386c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static IKeyVaultClient CreateKeyVaultWithManagedIdentity(string userIdentityId) | |
{ | |
AzureServiceTokenProvider azureServiceTokenProvider; | |
if (!string.IsNullOrEmpty(userIdentityId)) | |
{ | |
// use User Managed Identity | |
azureServiceTokenProvider = new AzureServiceTokenProvider($"RunAs=App;AppId={userIdentityId}"); | |
} else | |
{ | |
// use System Managed Identity | |
azureServiceTokenProvider = new AzureServiceTokenProvider(); | |
} | |
var keyVaultClient = new KeyVaultClient( | |
new KeyVaultClient.AuthenticationCallback( | |
azureServiceTokenProvider.KeyVaultTokenCallback)); | |
return keyVaultClient; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment