c# - 检索 Azure DevOps REST API 5.1 的 Accesstoken

标签 c# azure oauth-2.0 azure-devops

在我们的应用程序中,我们想要检索访问 token 。使用此 token ,我们希望使用 Azure DevOps Rest API 5.1 执行某些操作。

我已经尝试了 Microsoft 针对 OAuth2 ( https://learn.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops ) 和 PAT 的建议文档。结果总是返回 203 响应。有人知道这个问题的解决方法吗?

最佳答案

根据我的测试,我们可以使用 Azure Ad 访问 token 调用 Azure DevOps Rest API。欲了解更多详情,请引用以下步骤 1. 注册 Azure AD 应用程序 enter image description here

  • 配置应用程序

    a.创建客户端 key

    b.配置权限

    enter image description here

  • 获取 token

  •  # get code
    GET  https://login.microsoftonline.com/{tenant}/oauth2/authorize?
    client_id=<your app client id>
    &response_type=code
    &redirect_uri=<>
    &response_mode=query
    &resource=499b84ac-1321-427f-aa17-267ca6975798
    &state=12345
    
    #Get token
    Post https://login.microsoftonline.com/{tenant}/oauth2/token
    Content-Type: application/x-www-form-urlencoded
    grant_type=authorization_code
    &client_id=<>
    &code=<>
    &redirect_uri=https%3A%2F%2Flocalhost%3A12345
    &resource=499b84ac-1321-427f-aa17-267ca6975798
    &client_secret=<>
    
  • 调用 Rest API enter image description here
  • 关于c# - 检索 Azure DevOps REST API 5.1 的 Accesstoken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59609591/

    相关文章:

    Azure 开发运营 : policy for branch creation

    c# - Azure Service Fabric Actor 初始化

    node.js - 从 Azure AD 获取刷新 token 时出错

    c# - 在 Azure 队列存储中传递对象消息

    google-api - 使用 Google OAuth2.0 将登录电子邮件限制为特定域名

    asp.net - OpenIddict - 在同一项目中托管身份验证服务器和 Web api 资源

    c# - 更正 JSON 结果对象

    c# - 如何通过标签页名称关闭tabcontrol上的标签页

    c# - Delphi 函数转 C#

    c# - 按属性名从列表中选择常量