Condividi tramite


TemplateClient.GetSecretAsync(String, RequestContext) Method

Definition

[Protocol Method] Get a specified secret from a given key vault.

  • This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
public virtual System.Threading.Tasks.Task<Azure.Response> GetSecretAsync (string secretName, Azure.RequestContext context);
abstract member GetSecretAsync : string * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.GetSecretAsync : string * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function GetSecretAsync (secretName As String, context As RequestContext) As Task(Of Response)

Parameters

secretName
String

The name of the secret.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

secretName is null.

secretName is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

This sample shows how to call GetSecretAsync and parse the result.

TokenCredential credential = new DefaultAzureCredential();
TemplateClient client = new TemplateClient("<VaultBaseUrl>", credential);

Response response = await client.GetSecretAsync("<secretName>", null);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.ToString());

This sample shows how to call GetSecretAsync with all parameters and parse the result.

TokenCredential credential = new DefaultAzureCredential();
TemplateClient client = new TemplateClient("<VaultBaseUrl>", credential);

Response response = await client.GetSecretAsync("<secretName>", null);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("value").ToString());
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("contentType").ToString());
Console.WriteLine(result.GetProperty("tags").GetProperty("<key>").ToString());
Console.WriteLine(result.GetProperty("kid").ToString());
Console.WriteLine(result.GetProperty("managed").ToString());

Remarks

The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission.

Below is the JSON schema for the response payload.

Response Body:

Schema for SecretBundle:

{
  value: string, # Optional. The secret value.
  id: string, # Optional. The secret id.
  contentType: string, # Optional. The content type of the secret.
  tags: Dictionary<string, string>, # Optional. Application specific metadata in the form of key-value pairs.
  kid: string, # Optional. If this is a secret backing a KV certificate, then this field specifies the corresponding key backing the KV certificate.
  managed: boolean, # Optional. True if the secret's lifetime is managed by key vault. If this is a secret backing a certificate, then managed will be true.
}

Applies to