Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DevOps : Non-Interactive login in new DevOps(VSTS) not working getting error 'TF30063: You are not authorized to access

I am trying to connect to Azure DevOps previously known as VSTS using c#. I want to connect to it without the login screen of azure DevOps. I am currently trying the following code but some how it is not working

        NetworkCredential netCred = new NetworkCredential("[email protected]", "test");
        Uri tfsuri = new Uri("https://dev.azure.com/test10");
        VssBasicCredential bsCred = new VssBasicCredential(netCred);
        VssCredentials vssCred = new VssClientCredentials(bsCred);

        TfsTeamProjectCollection collection = new TfsTeamProjectCollection(tfsuri, vssCred);

        collection.Authenticate();

        var witClient = collection.GetClient<ProjectHttpClient>();
        var listOfProjects = witClient.GetProjects().Result;

libraries I am using

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Operations;
using Microsoft.VisualStudio.Services.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;

The code prompts a login screen, on which if I enter the password the auth still does not work. I dont want the login screen to appear and only want to connect with the username and password.

With alternate credentials this method is working but it is not my requirement and I can not use alternate credentials.

I have tried following the samples from the official site but no solution is working for the new DevOps.

Any Solution how can I authenticate with usernanme/password in the new DevOps without the login screen

like image 698
Student Avatar asked Nov 13 '18 21:11

Student


People also ask

Is Azure DevOps and VSTS same?

Visual Studio Team Services is now Azure DevOps Services Continuous integration and continuous delivery (CI/CD) that works with any language, platform, and cloud. Unlimited cloud-hosted private Git and Team Foundation Version Control (TFVC) repositories for your project.

Is TFS and VSTS are same?

Today, VSTS (Visual Studio Team Services) is Microsoft's Git code hosting, collaboration, and DevOps platform. It offers features comparable to other cloud-based Git tools and is the default version control system in Visual Studio. The on-premises version of VSTS is now called TFS.

Is VSTS a DevOps tool?

Visual Studio Team Services (VSTS) -- rebranded as Azure DevOps in 2018 -- is an Azure cloud-hosted extension of Microsoft's Team Foundation Server (TFS) -- now called Azure DvOps -- that assist development teams with special tools and services for software programmers, analysts and testers as well as IT project or ...


1 Answers

The class TfsTeamProjectCollection is from the old .Net libraries, try the new Azure DevOps .Net libraries, and you can authenticate in a few ways:

NTLM

The most basic one is constructing a VssCredentials instance with no parameter at all and what you’ll be using is simply put integrated authentication / NTLM:

var visualStudioServicesConnection = new VssConnection(new Uri(baseUri), new VssCredentials());

Basic Authentication

VSTS and TFS also provide means to utilize Basic authentication (HTTP AUTH) which you need to create and enable first (see VSTS guidelines) and once you’ve done so, you can use them via the API like this:

var visualStudioServicesConnection = new VssConnection(new Uri(baseUri), new VssBasicCredential(username, password));

Personal Access Tokens

Next up are Personal Access Tokens (PAT) which you can easily create following the VSTS guidelines and those PATs are a means of authenticating separately from your actual credentials with a fine-grained & per access token scopes of security. Simply put it allows you to create a PAT for every use-case or even application and thereby enabling a secure and clearly separated way of giving an application or 3rd party access to your VSTS or TFS system on your behalf.

To use these via the API, you use the exact same mechanism as via Basic Authentication but you simply don’t provide any username (well – an empty one to be precise), and the PAT itself is used as the password:

var visualStudioServicesConnection = new VssConnection(new Uri(baseUri), new VssBasicCredential(string.Empty, pat));

Visual Studio Sign-in Prompt

Moreover, another way of authenticating is using the standard VS Sign-In prompt which is similarly easy and exposed via the VssClientCredentials class:

var visualStudioServicesConnection = new VssConnection(new Uri(baseUri), new VssClientCredentials());

OAuth Authentication

OAuth is a widely used but a slightly more tedious authorization protocol to implement but luckily there’s a thorough sample application available at CodePlex specifically for VSTS / VSO (which also works for on-premises).

Once you have the corresponding access token, you can use it to VSTS / TFS utilizing the VssOAuthCredential class:

var visualStudioServicesConnection = new VssConnection(new Uri(baseUri), new VssOAuthCredential(accessToken));

Azure Active Directory Authentication

Last but not least you can utilize Azure Active Directory identities to authenticate against a VSTS or TFS system via the VssAadCredential class:

var visualStudioServicesConnection = new VssConnection(new Uri(baseUri), new VssAadCredential(username, password));
like image 117
Shayki Abramczyk Avatar answered Sep 19 '22 18:09

Shayki Abramczyk