如何简单地获取不记名令牌以向 Azure DevOps API 发送请求?
How to simply get a bearer token to send requests to Azure DevOps API?
我需要创建一个组织源来托管在我们的 Azure DevOps 环境中的项目之间共享的 nuget 包。
经过几次不成功的尝试和研究,我发现创建组织提要的唯一方法是微软口中设计的 Azure DevOps API。
索赔来源:This question on VS dev community
和 The MS docs on project-scoped feeds
基本上,我只需要能够在这里执行 POST:
https://feeds.dev.azure.com/{组织}/_apis/packaging/feeds?api-version=5.1-preview.1
正文:
{
"name": "{myfeedname}",
"hideDeletedPackageVersions": true,
"upstreamEnabled": true
}
当然,还有一个 Bearer 令牌来验证我自己。这就是我感到困惑的地方。
获得一个最简单的方法是什么?我在 Azure DevOps 的计算机浏览器上通过我公司的 Microsoft AD 帐户登录。在我的浏览器开发工具中,我没有看到任何可以 "steal" 在 PostMan 中使用的 Bearer 令牌。
API docs 描述了一些相关信息,但我对如何在 Postman 中使用它感到困惑:
Security oauth2
Type: oauth2
Flow: accessCode
Authorization URL: https://app.vssps.visualstudio.com/oauth2/authorize&response_type=Assertion
Scopes Name Description
vso.packaging_write Grants the ability to
create and read feeds and packages.
这是 OAuth2 的 Postman 界面:
我可以看到文档中的信息与字段 1 - 2 - 3 - 4 的关系,但是,我应该使用什么回调 url?什么凭据?我的 Microsoft 电子邮件 + 来自 AD 的密码?
我试过了,我似乎得到的只是来自 Postman 的信息:
{"$id":"1","innerException":null,"message":"A potentially dangerous Request.Path value was detected from the client (&).","typeName":"System.Web.HttpException, System.Web","typeKey":"HttpException","errorCode":0,"eventId":0}
TLDR
我如何正确地继续使用 Postman 或其他工具获取令牌以手动执行我对 Azure DevOps REST 的一次性请求 API?
备注:
这里有以下信息:Unable to get Authorization code for Devops using Postman oAuth2.0
,领先于此:https://github.com/Microsoft/azure-devops-auth-samples/tree/master/OAuthWebSample,我知道我必须注册并 运行 整个网络应用程序。我理解正确吗?我有更简单的方法吗?
I understand that I have to register and run a whole web application. Am I understanding this correctly ? I there a simpler way ?
是的,你是对的。您必须注册整个网络应用程序。
作为OAuth2
在Postman中的接口,我们需要提供CallbackUrl
、ClientID
、ClientSecret
等。然后,我们查看文档Requesting an OAuth 2.0 token,可以知道Callback URL
是:
The client application callback URL redirected to after auth, and that
should be registered with the API provider.
因此,我们必须在 Azure DevOps (https://app.vsaex.visualstudio.com/app/register) 中注册一个 OAuth 客户端应用程序,然后我们可以获得以下信息,例如:
您可以查看文档 Authorize access to VSTS REST APIs with OAuth 2.0 了解更多详细信息。
据我所知,目前没有更简单的方法来获取不记名令牌以向 Azure DevOps 发送请求API。
希望对您有所帮助。
我需要创建一个组织源来托管在我们的 Azure DevOps 环境中的项目之间共享的 nuget 包。
经过几次不成功的尝试和研究,我发现创建组织提要的唯一方法是微软口中设计的 Azure DevOps API。
索赔来源:This question on VS dev community 和 The MS docs on project-scoped feeds
基本上,我只需要能够在这里执行 POST: https://feeds.dev.azure.com/{组织}/_apis/packaging/feeds?api-version=5.1-preview.1
正文:
{
"name": "{myfeedname}",
"hideDeletedPackageVersions": true,
"upstreamEnabled": true
}
当然,还有一个 Bearer 令牌来验证我自己。这就是我感到困惑的地方。
获得一个最简单的方法是什么?我在 Azure DevOps 的计算机浏览器上通过我公司的 Microsoft AD 帐户登录。在我的浏览器开发工具中,我没有看到任何可以 "steal" 在 PostMan 中使用的 Bearer 令牌。
API docs 描述了一些相关信息,但我对如何在 Postman 中使用它感到困惑:
Security oauth2
Type: oauth2
Flow: accessCode
Authorization URL: https://app.vssps.visualstudio.com/oauth2/authorize&response_type=Assertion
Scopes Name Description
vso.packaging_write Grants the ability to create and read feeds and packages.
这是 OAuth2 的 Postman 界面:
我可以看到文档中的信息与字段 1 - 2 - 3 - 4 的关系,但是,我应该使用什么回调 url?什么凭据?我的 Microsoft 电子邮件 + 来自 AD 的密码?
我试过了,我似乎得到的只是来自 Postman 的信息:
{"$id":"1","innerException":null,"message":"A potentially dangerous Request.Path value was detected from the client (&).","typeName":"System.Web.HttpException, System.Web","typeKey":"HttpException","errorCode":0,"eventId":0}
TLDR
我如何正确地继续使用 Postman 或其他工具获取令牌以手动执行我对 Azure DevOps REST 的一次性请求 API?
备注:
这里有以下信息:Unable to get Authorization code for Devops using Postman oAuth2.0 ,领先于此:https://github.com/Microsoft/azure-devops-auth-samples/tree/master/OAuthWebSample,我知道我必须注册并 运行 整个网络应用程序。我理解正确吗?我有更简单的方法吗?
I understand that I have to register and run a whole web application. Am I understanding this correctly ? I there a simpler way ?
是的,你是对的。您必须注册整个网络应用程序。
作为OAuth2
在Postman中的接口,我们需要提供CallbackUrl
、ClientID
、ClientSecret
等。然后,我们查看文档Requesting an OAuth 2.0 token,可以知道Callback URL
是:
The client application callback URL redirected to after auth, and that should be registered with the API provider.
因此,我们必须在 Azure DevOps (https://app.vsaex.visualstudio.com/app/register) 中注册一个 OAuth 客户端应用程序,然后我们可以获得以下信息,例如:
您可以查看文档 Authorize access to VSTS REST APIs with OAuth 2.0 了解更多详细信息。
据我所知,目前没有更简单的方法来获取不记名令牌以向 Azure DevOps 发送请求API。
希望对您有所帮助。