本文介绍了本地运行的VSTS构建-错误:"Microsoft Internet Explorer.增强的安全配置"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Windows 10并编写脚本来处理/启动VSTS构建.

I'm running Windows 10 and making a script to handle/start VSTS builds.

示例调用(用于测试的替代属性):

Sample call (overriding properties for testing):

$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = "https://mytenancy.visualstudio.com/"
$env:SYSTEM_TEAMPROJECTID = "Project1"
$env:SYSTEM_DEFINITIONID = 5
#$env:SYSTEM_ACCESSTOKEN = "mytoken" - uncomment when running locally

$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/definitions/$($env:SYSTEM_DEFINITIONID)?api-version=2.0"
Write-Host "URL: $url"
$definition = Invoke-RestMethod -Uri $url -Headers @{
    Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "Definition = $($definition | ConvertTo-Json -Depth 100)"
"Authenticated"

此脚本在服务器上工作正常,但是如果取消注释$env:SYSTEM_ACCESSTOKEN并在本地运行,则会出现以下错误:

This script works fine on the server, but if I uncomment the $env:SYSTEM_ACCESSTOKEN and run locally, I get the following error:

我正在运行Windows 10.

I'm running Windows 10.

我尝试了很多事情,包括:

I've tried many things, including:

  • 在Internet选项中关闭尽可能多的安全性.
  • 新鲜令牌
  • 将令牌转换为安全字符串
  • 按照对
  • Turning off as much security as possible in Internet Options.
  • Fresh Token
  • Converting the token to a secure string
  • Converting to a Base64 string as detailed in the answer to this post

如何在本地进行身份验证?

How can I authenticate locally?

编辑(以下为接受的答案)

接受的答案解决了问题.我认为这里的两个关键点是:

The accepted answer solved the problem. I think the two key points here were:

  • 转换为Base64时的正确编码
  • 以这种方式(本地)运行时,将身份验证从Bearer更改为Basic.
  • The correct encoding in conversion to Base64
  • Changing authentication from Bearer to Basic when running in this way (locally).

最终代码:

$user = "[username]"
$accessToken="[token]"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$accessToken)))
$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = "https://mytenancy.visualstudio.com/"
$env:SYSTEM_TEAMPROJECTID = "Project1"

$checkBuildUrl = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$($env:SYSTEM_TEAMPROJECTID)/_apis/build/builds/$($requestedBuildId)?api-version=2.0"

$buildStatus = Invoke-RestMethod -Uri $checkBuildUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

推荐答案

创建一个新的访问令牌,并参考以下代码通过PowerShell调用REST API:

Create a new access token and refer to this code to call the REST API through PowerShell:

$user = "[anything]"
$accessToken="[access token]"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$accessToken)))
...
Invoke-RestMethod -Uri $uri -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $bodyJson

关于增强的安全性,存在类似的问题:

Regarding enhanced security, there is a similar issue:

在Visual Studio中增强了安全性错误Team Services Rest API

这篇关于本地运行的VSTS构建-错误:"Microsoft Internet Explorer.增强的安全配置"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 03:01