Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure KeyVault过期日期更新_C#_Azure_Azure Keyvault - Fatal编程技术网

C# Azure KeyVault过期日期更新

C# Azure KeyVault过期日期更新,c#,azure,azure-keyvault,C#,Azure,Azure Keyvault,是否可以在不通过Microsoft.Azure.KeyVault包在KeyVault中创建新版本的机密的情况下更新机密的过期日期?我可以在Azure门户中执行此操作,但需要能够以编程方式执行此操作。是的,可以在不创建新版本的情况下更新现有机密的过期日期 这是一个快速而肮脏的C#代码示例。仔细查看正在调用的SecretAttributes和client.UpdateSecretAsync方法 Expires是需要设置的机密的属性 我在利用 结果是,由于我已经在使用UpdateCretasync方

是否可以在不通过Microsoft.Azure.KeyVault包在KeyVault中创建新版本的机密的情况下更新机密的过期日期?我可以在Azure门户中执行此操作,但需要能够以编程方式执行此操作。

是的,可以在不创建新版本的情况下更新现有机密的过期日期

这是一个快速而肮脏的C#代码示例。仔细查看正在调用的
SecretAttributes
client.UpdateSecretAsync
方法

Expires
是需要设置的机密的属性

我在利用


结果是,由于我已经在使用UpdateCretasync方法,它正在更新,只是Azure portal没有刷新值,即使我单击了提供的刷新按钮-最终页面重新加载显示值已被刷新updated@CraigM这是有道理的。我也见过这种情况发生在门户端。
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.KeyVault.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

namespace UpdateKeyVaultSecret
{
    class Program
    {
        static void Main(string[] args)
        {
            UpdateSecretAttributes("https://rohitvault1.vault.azure.net/secrets/mysecret1").GetAwaiter().GetResult();

            Console.ReadLine();
        }


        private static async Task<string> GetAccessTokenAsync(string authority, string resource, string scope)
        {
            var authContext = new AuthenticationContext(authority);
            ClientCredential clientCred = new ClientCredential("<my-app-clientid>", "<my-app-client-secret>");
            AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred);

            if (result == null)
                throw new InvalidOperationException("Failed to obtain the JWT token");

            return result.AccessToken;
        }

        public static async Task<string> GetSecretFromVault(string secretKeyIdentifier)
        {
            var client = new KeyVaultClient(
                new KeyVaultClient.AuthenticationCallback(GetAccessTokenAsync),
                new System.Net.Http.HttpClient());

            var secret = await client.GetSecretAsync(secretKeyIdentifier).ConfigureAwait(false);

            return secret.Value;
        }

        public static async Task<string> UpdateSecretAttributes(string secretKeyIdentifier)
        {
            var client = new KeyVaultClient(
                new KeyVaultClient.AuthenticationCallback(GetAccessTokenAsync),
                new System.Net.Http.HttpClient());

            SecretAttributes attributes = new SecretAttributes();
        attributes.Expires = DateTime.UtcNow.AddDays(15);

            var secret = await client.UpdateSecretAsync(secretKeyIdentifier, null, attributes, null).ConfigureAwait(false);

            return secret.Value;
        }
    }
}
az keyvault secret set-attributes --vault-name 'rsvault1' --name 'secret123' --expires '2018-12-25T01:23:45Z'