コード例 #1
0
        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");
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        public void ManagedIdentityCredentialTest(string clientId)
        {
            var credential = AzureOauthTokenAuthentication.GetOauthTokenCredentialFromManagedIdentity(clientId);

            Assert.IsNotNull(credential, "Credential should not be null");
        }
コード例 #4
0
 public void ManagedIdentityCredential1FailureTest(string clientId)
 {
     var credential = AzureOauthTokenAuthentication.GetOauthTokenCredentialFromManagedIdentity(clientId);
 }