i have some problems trying to use a bearer token when calling a rest api.
I tried two methods with the same result:
Method 1
I created an app registration in the azure portal, and gave it permissions to use devops api with user impersonation.
Method 2
I created an app in https://app.vsaex.visualstudio.com/ and gave it project/teams management permission.
Code
For my code, i used this (works when i use PAT to authenticate)
import requests
ADOtoken = 'obtained by microsoft example'
org = 'myorg'
projectName = 'test'
headers = {"Authorization": f"Bearer {ADOtoken}"}
requesturl = f"https://dev.azure.com/{org}/_apis/projects?api-version=6.0"
data = {
"name": projectName,
"description": "description is requred",
"capabilities": {
"versioncontrol": {
"sourceControlType": "Git"
},
"processTemplate": {
"templateTypeId": "6b724908-ef14-45cf-84f8-768b5384da45"
}
}
}
r = requests.post(requesturl, json = data, headers=headers)
Getting the token
I get the token by using this example: https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-v2-python-webapp
I changed the scope to ['https://app.vssps.visualstudio.com/user_impersonation']
expected result
I expected to get an error to debug, or the project to be created
actual result
I get a 203 (redirect) and content is the azure devops login site