user1335978
user1335978

Reputation: 193

Getting TF30063: You are not authorized to access https://{url}.visualstudio.com/

I am using the below code to talk to visual studio online project to get the list of work items. but getting TF30063 unauthorized access error.

I have tried access the project using Network creds, windows default creds, VssBasicCredential, and VssCredentials. I tried clearing the cache, Generic creds. but nothing is working. I am able to access the VSO project from the browser but not through this code.

Let me know if I am missing anything.

Appreciate your help. thanks

        this.uri = projectUri;
        string userName = ConfigurationManager.AppSettings["Username"];
        string password = ConfigurationManager.AppSettings["Password"];

        NetworkCredential netCred = new NetworkCredential(userName, password);
       // VssBasicCredential bsCred = new VssBasicCredential(netCred);
       //VssCredentials vssCred = new VssCredentials(bsCred);
       // VssCredentials vssCred = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(netCred));           

        tpc = new TfsTeamProjectCollection(new Uri(uri), netCred);

        workItemStore = WorkItemStore)tpc.GetService(typeof(WorkItemStore));

Upvotes: 2

Views: 2827

Answers (2)

John Holliday
John Holliday

Reputation: 1308

This can happen when the default credentials on your machine don't match the credentials associated with the current solution. You can fix this by manually signing in from within Visual Studio. Open a WebBrowser view (Ctrl+W, W) and then navigate to the dev.azure.com page for the account you wish to use. Sign in normally via the browser view. Team Explorer will then pick up the correct credentials.

Upvotes: 0

Andy Li-MSFT
Andy Li-MSFT

Reputation: 30362

Just try to enable alternate credentials for your account. Then try it again.

You can also reference this article : How to connect to TF Service without a prompt for LiveID credentials

Below sample for your reference to get the list of work items, it works on my side:

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;

namespace GetWorkItemList
{
    class Program
    {
        static void Main(string[] args)
        {

            string info = String.Empty;

            NetworkCredential netCred = new NetworkCredential("[email protected]", "password");      

            var tpc = new TfsTeamProjectCollection(new Uri("https://xxxx.visualstudio.com"), netCred);

            WorkItemStore workItemStore = new WorkItemStore(tpc);

            Query query = new Query(workItemStore, "SELECT * FROM WorkItems WHERE [System.TeamProject] = @project", new Dictionary<string, string>() { { "project", "ProjectNameHere" } });

            WorkItemCollection wic = query.RunQuery();

            foreach (WorkItem item in wic)
            {
                info += String.Format("WIT:{0} ID: {1}  Title: {2}\n", item.Type.Name, item.Id, item.Title);
            }

            Console.WriteLine(info);
            Console.ReadLine();
        }
    }
}  

Besides, you can also try using PAT, click below link to see the sample:

Fetch work items with queries programatically in VSTS

enter image description here

Upvotes: 2

Related Questions