public void ManagedIdentityBaseWithOptionsTest(bool useHostString) { var options = AzureOauthTokenAuthentication.GetOptions(useHostString ? AzureOauthTokenAuthentication.DefaultAuthorityHost : null); var credential = AzureOauthTokenAuthentication.GetOauthTokenCredentialFromManagedIdentity(options); Assert.IsNotNull(credential, "Credential should not be null"); }
public static KeyVaultSecrets GetSecretsClient(ILogger logger) { var keyVaultName = Environment.GetEnvironmentVariable("KeyVaultName"); var hubSecretName = Environment.GetEnvironmentVariable("HubSecretName"); var identityClientId = Environment.GetEnvironmentVariable("IdentityClientId"); var tenantId = Environment.GetEnvironmentVariable("TenantId"); var clientId = Environment.GetEnvironmentVariable("ClientId"); var clientSecret = Environment.GetEnvironmentVariable("ClientSecret"); logger.LogInformation("Retrieving secrets from vault named: {valueName} and a hub secret named: {hubSecretName}", keyVaultName, hubSecretName); TokenCredential tokenProvider; if (string.IsNullOrWhiteSpace(clientSecret)) { tokenProvider = string.IsNullOrWhiteSpace(identityClientId) ? AzureOauthTokenAuthentication.GetOauthTokenCredentialFromManagedIdentity() : AzureOauthTokenAuthentication.GetOauthTokenCredentialFromManagedIdentity(identityClientId); } else { tokenProvider = AzureOauthTokenAuthentication.GetOauthTokenCredentialFromClientSecret(tenantId, clientId, clientSecret); } logger.LogInformation("Completed creation of token provider"); var vault = new KeyVault(keyVaultName, tokenProvider, 3, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(10)); logger.LogInformation("Created key vault"); return(vault.GetSecretsClient()); }
public void ManagedIdentityCredentialTest(string clientId) { var credential = AzureOauthTokenAuthentication.GetOauthTokenCredentialFromManagedIdentity(clientId); Assert.IsNotNull(credential, "Credential should not be null"); }
public void ManagedIdentityCredential1FailureTest(string clientId) { var credential = AzureOauthTokenAuthentication.GetOauthTokenCredentialFromManagedIdentity(clientId); }