Freigeben über


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());

Applies to