VSTS Authenticating with vssClientCredentials

2019-06-03 07:56发布

问题:

I am currently trying to connect to a VSTS project using the code below, I have previously connected successfully after entering credentials into the dialog box shown.

if (!IsConnected)
{
    sourceControl = release.SourceControl;
    connection = new VssConnection(new Uri(sourceControl), new VssClientCredentials());
    workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>();
}

The dialog box is no longer shown and an exception is thrown:

TF400813: Resource not available for anonymous access. Client authentication required.

I am unaware of any changes that could have caused this to break, any help would be greatly appreciated.

回答1:

You can delete the cached credential from registry: Computer\HKEY_CURRENT_USER\Software\Microsoft\VSCommon\14.0\ClientServices\TokenStorage\VisualStudio (delete VssApp key)

You also can specify the credential storage:

var c = new VssClientCredentials();
c.Storage = new VssClientCredentialStorage(storageKind: "VssApp2", storageNamespace: "VisualStudio");
connection = new VssConnection(new Uri(sourceControl), c);