Search code examples
azurepfxsecret-keyazure-keyvaultazure-resource-manager

How to use the secret uri to get the secret value stored in the azure keyvault?


By using the ARM API's I am able to fetch the secret uri of the secret stored in azure keyvault

 https://management.azure.com/subscriptions/{mySubID}/resourceGroups/{myResourcegroup}/providers/Microsoft.KeyVault/vaults/{myvaultName}/secrets/{mycert}?api-version=2015-06-01

But I wanted a secret value to form a PFX cert inorder to upload to a service.

How can I achieve this ?

Please help !! Thanks in advance ....


Solution

  • This worked for me

    GET https://{vaultBaseUrl}/secrets/{secret-name}/{secret-version}?api-version={api-version}
    

    Refernce: https://learn.microsoft.com/en-us/rest/api/keyvault/getsecret

    NOTE:

    I was not successful with this in the beginning, later found out that I was using the token obtained from https://management.core.windows.net

    Apparently it failed saying like InvalidAuthenticationTokenAudience :The access token has been obtained from wrong audience or resource

    So remember you have to get the token from https://vault.azure.net