Read key vault secret d365 in CRT extension
If you want to read the key vault secret in the D365 CRT extension, Follow the following steps;
- First, we have to configure the Key vaults on the D365 HQ side.
- On the CRT Side you have to implement a class in which you have to write the method below;
public static async Task<string> GetKeyVaultValueAsync(string keyVaultName, RequestContext requestContext)
{
if (string.IsNullOrEmpty(keyVaultName))
{
throw new ArgumentNullException("keyVaultName");
}
string vaultValue = string.Empty;
try
{
GetUserDefinedSecretStringValueServiceRequest keyVaultRequest = new GetUserDefinedSecretStringValueServiceRequest(keyVaultName);
GetUserDefinedSecretStringValueServiceResponse keyVaultResponse = await requestContext.ExecuteAsync<GetUserDefinedSecretStringValueServiceResponse>(keyVaultRequest).ConfigureAwait(false);
if (keyVaultResponse != null)
{
vaultValue = keyVaultResponse.SecretStringValue;
}
return vaultValue;
}
catch (Exception ex)
{
string message = $"Unable to read Key vault secret:'{keyVaultName}', message:'{ex.Message}'.";
throw new CommerceException("GetVaultValue", message);
}
}
- Below is the line to read the key vault secret;
string abcURL= await KeyVaultClass.GetKeyVaultValueAsync(ABCKEYVAULTConfigureInHQ, request.RequestContext).ConfigureAwait(false);
Comments