【Azure Key Vault】使用REST API调用Azure Key Vault Secret的示例步骤

准备阶段

1)准备Microsoft Entra ID的注册应用(Service Principal),如没有,需要注册它:Register an application - Microsoft Azure 由世纪互联运营

如取名“GetKeyVaultSecretVault01”,具体操作步骤,请参考:https://docs.azure.cn/zh-cn/entra/identity-platform/quickstart-register-app#register-an-application

2)在Key Vault的Access Policy页面中,赋予Microsoft Entra ID的注册应用(Service Principal)的访问权限,具体操作步骤,请参考:https://docs.azure.cn/zh-cn/key-vault/general/assign-access-policy-portal

 

第一步:准备Microsoft Entra ID获取Token的URL和Body

POST URL: https://login.partner.microsoftonline.cn/<YourTenantID>/oauth2/v2.0/token 

其中body的值

grant_type : client_credentials

client_id : <your Service Principal Client ID>

client_secret : <your Service Principal Secret Value>

scope :  https://vault.azure.cn/.default

注:<YourTenantID> , <your Service Principal Client ID> , <your Service Principal Secret Value> 需要从Entra ID注册应用页面获取

 

第二步:从第一步中获取Key Vault的Authorization Token

发送API,获取Token。使用任意一种API发送工具即可,这里使用的VS Code小插件 Thunder Client

 

第三步:请求Key Vault Secret URL,获取机密值

GET URL: https://<YourKeyVault>.vault.azure.cn/secrets/<SecretName>?api-version=7.4 

将第二步中的Token值加入Authorization的中

注:<YourKeyVault> , <SecretName> 需要替换成正确的Key Vault/Secret名。

 

参考资料

将应用程序注册到 Microsoft 标识平台 :https://docs.azure.cn/zh-cn/entra/identity-platform/quickstart-register-app#register-an-application

使用 Azure 门户分配 Key Vault 访问策略:https://docs.azure.cn/zh-cn/key-vault/general/assign-access-policy-portal

Get Secret : https://learn.microsoft.com/zh-cn/rest/api/keyvault/secrets/get-secret/get-secret?view=rest-keyvault-secrets-7.4&tabs=HTTP

 

[END]

 

posted @   路边两盏灯  阅读(122)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2021-03-05 【Azure 云服务】Azure Cloud Service在发布新部署后遇见不能RDP(远程连接)到实例时如何处理?
点击右上角即可分享
微信分享提示