微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为 rest api 创建自定义 Azure DevOps 服务连接

如何解决为 rest api 创建自定义 Azure DevOps 服务连接

我在 Internet 上有一个受 Azure AD 保护的 REST API 和一个必需的标头(自定义 apikey)。 您可以在 postman 示例中使用客户端凭据流调用此 API。这一切正常。

我现在正在开发一个自定义 Azure DevOps 扩展,它以 ADO 的工作项形式显示从该 API 返回的信息。我可以通过通用服务连接从扩展中调用 API(如果我从 API 中删除安全性)。现在我想让安全工作。

所以我想创建一个自定义服务连接,它将使用 ClientID 和 ClientSecret(客户端凭据流)从 azure AD 获取访问令牌。 当我开始工作时,我可以以安全的方式调用我的 API。 另外,如何将强制性标头添加到对 api 的调用中?我还需要将标题作为字段添加到服务连接中,对吗? 所以我想我最终会得到一个请求 TenantIdClientIdClient SecretAudience/ScopeList 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?