Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTS - Where has 'Allow Scripts to Access OAuth Token' gone?

I have VSTS builds that use the Powershell script to access the VSTS API, similar to that detailed in Microsoft's Documentation.

The document states:

To enable your script to use the build process OAuth token, go to the Options tab of the build definition and select Allow Scripts to Access OAuth Token.

After you've done that, your script can use to SYSTEM_ACCESSTOKEN environment variable to access the VSTS REST API. For example:

Example:

$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build-release/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 1000)"

As detailed in Microsofts Documentation, I'm sure you used to go to Build > Options and click 'Allow Scripts to Access OAuth Token', but it is no longer there (see pic below).

enter image description here

When I try a build I get the following (which doesn't happen for my old builds):

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"TF400813: The user '' is not authorized to access this

In addition, when I clone a build (which worked nicely when I did it 3 months ago), the property is set to false (it's set to true on the original).

enter image description here

UPDATE: If I export from VSTS, change that property and import again, it works, but I really need a solution without this sort of manual intervention.

How should this be done now please?

like image 437
JsAndDotNet Avatar asked Jun 07 '18 12:06

JsAndDotNet


People also ask

How do I allow scripts to access the OAuth token?

Allow scripts to access the OAuth tokenSelect this check box in classic build pipelines if you want to enable your script to use the build pipeline OAuth token. This check box is located under the "additional settings" section after selecting the agent job in the pipeline.

How do I allow scripts to access OAuth token from Yaml builds?

To enable scripts to use the build process OAuth token, go to the Options tab of the build definition and select Allow Scripts to Access OAuth Token . For more information, read Azure DevOps: Use the OAuth token to access the REST API.

Where are oauth2 tokens stored?

The client, in OAuth terminology, is the component that makes requests to the resource server, in your case, the client is the server of a web application (NOT the browser). Therefore, the access token should be stored on the web application server only.


1 Answers

It is available in the agent phase now

enter image description here

like image 80
ChamindaC Avatar answered Oct 30 '22 17:10

ChamindaC