问题描述
我在 Internet 上有一个受 Azure AD 保护的 REST API 和一个必需的标头(自定义 apikey)。 您可以在 postman 示例中使用客户端凭据流调用此 API。这一切正常。
我现在正在开发一个自定义 Azure DevOps 扩展,它以 ADO 的工作项形式显示从该 API 返回的信息。我可以通过通用服务连接从扩展中调用 API(如果我从 API 中删除安全性)。现在我想让安全工作。
所以我想创建一个自定义服务连接,它将使用 ClientID 和 ClientSecret(客户端凭据流)从 azure AD 获取访问令牌。
当我开始工作时,我可以以安全的方式调用我的 API。
另外,如何将强制性标头添加到对 api 的调用中?我还需要将标题作为字段添加到服务连接中,对吗?
所以我想我最终会得到一个请求 TenantId
、ClientId
、Client Secret
、Audience/Scope
、List of headers (name/value)
的自定义服务连接实例。
为了获得更多参考博客文章,我使用了这个:https://thingswithcode.blogspot.com/2019/07/using-azure-devops-service-connections.html
{
"id": "api-service-connection","description": "Service connection for api","type": "ms.vss-endpoint.service-endpoint-type","targets": [
"ms.vss-endpoint.endpoint-types"
],"properties": {
"name": "Call API","displayName": "Call API","icon": "img/world.png","url": {
"displayName": "API Url","value": "https://path-to-api","helpText": "Url of the API to connect to."
},"inputDescriptors": [
{
"id": "api-key","name": "API Key","description": "The value for the header 'ApiKey'","inputMode": "textBox","isConfidential": false,"validation": {
"isrequired": true,"dataType": "string"
}
}
],"authenticationSchemes": [
{
"type": "ms.vss-endpoint.endpoint-auth-scheme-oauth2" // this is wrong...
}
],"headers": [
{
"name": "ApiKey","value": "{{endpoint.api-key}}"
}
],"helpMarkDown": "<a href=\"" target=\"_blank\"><b>Learn more</b></a>"
}
}
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)