azure-devopsazure-devops-rest-api

How to validate azure PAT token thru REST API


I am trying to validate the PAT token thru REST api, just wanted to make sure the PAT token has board access

I tried this API

POST https://dev.azure.com/1000057326/_apis/security/permissionevaluationbatch?api-version=7.1-preview.1

request body:

{
  "evalBatch": [
    {
      "securityNamespaceId": "{id}",
      "token": "{PAT}",
      "permissions": "2,4,8,16"
    }
  ]
}

But nothing giving any result. Is there a azure devops REST API to check if my PAT token has necessary permissions


Solution

  • The simplest method to verify if a Personal Access Token (PAT) has access to Board is by using it to make a request to the Board's REST API. A 200 status code indicates that the PAT has the required permissions, while a 401 status code means that the PAT lacks access.

    You can also refer the API in this answer, it will return the list of the PATs with the scope. Then you can check the PAT scope of each PAT. You just need to grant the "Token Administration" scope to the personal access token to run it.

    https://vssps.dev.azure.com/Org name/_apis/Token/SessionTokens?displayFilterOption=1&createdByOption=3&sortByOption=3&isSortAscending=true&startRowNumber=1&pageSize=100&api-version=5.0-preview.1
    

    scope