Home > other >  Execute RestAPI Azure DevOps Services - Authentication with username & Password no PAT
Execute RestAPI Azure DevOps Services - Authentication with username & Password no PAT

Time:06-21

Can i Use User/Password combination to run RestAPI to Azure DevOps Services?

Short answer NO. - see explanation at marked answer

I tried to find a way to get RestAPI working without PAT or Create a Token from Current Login Info and failed

The following Code Return 401:

using System.Net;

byte[] bytes = System.Text.Encoding.ASCII.GetBytes("user:password");
string patEncoded = Convert.ToBase64String(bytes);

var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://dev.azure.com/<ORG>/_apis/wit/workitems/22289?api-version=6.0");
httpWebRequest.Headers.Add("Authorization", "Basic "   patEncoded);

httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "GET";

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();



var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

Any Advice is much appreciated

  1. I do not want to create an app and register it on the tenant .

CodePudding user response:

Authenticate your web app users for REST API access, so your app doesn't continue to ask for usernames and passwords. Azure DevOps Services uses the OAuth 2.0 protocol to authorize your app for a user and generate an access token. Use this token when you call the REST APIs from your application.

For the Authentication mechanism, REST API is using the mention-aboved authentication mechanism to be authentication.

userName & password: Azure DevOps no longer supports Alternate Credentials authentication since the beginning of March 2, 2020. Here is the document.

  • Related