如何解决为 rest api 创建自定义 Azure DevOps 服务连接
我在 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 举报,一经查实,本站将立刻删除。