TF30063: You are not authorized … programmatic access not working

喜你入骨 提交于 2019-12-10 18:40:01

问题


The code below provided in this answer did work well for a while but now its throwing Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: 'TF30063: You are not authorized to access https://{mysite}.visualstudio.com/.' again.

var credentials = new VssClientCredentials();
credentials.PromptType = CredentialPromptType.PromptIfNeeded;

var teamProjects = new TfsTeamProjectCollection(tfsCollectionUri, credentials);
teamProjects.EnsureAuthenticated();         // exception thrown

Q How can I fix this problem?

Update Strange enough,

  1. before executing teamProjects.EnsureAuthenticated(); the debugger reads PromptIfNeeded for credentials.PromptType.
  2. after the exception has been thrown and the debugger has stopped the execution, it reads DoNotPrompt for credentials.PromptType.

Observation The above code works perfectly well in a console application but fails to work in a windows forms application (i.e. it throws an exception).

Q1 How can I make the above code work in a windows forms application?


回答1:


If you execute the code above within a Task (i.e. a separate thread) it just works. If the credentials are not present or stale at the location in the registry (see this answer) a window opens and you can authenticate yourself.

Can anyone explain why this works?




回答2:


VS has added a registry entry to store the credential, try to delete the entry in the following path:

HKEY_CURRENT_USER\Software\Microsoft\VSCommon\14.0\ClientServices\TokenStorage\VisualStudio\VssApp

Update:

Also, try the code below to see whether it works:

 var credentials = new VssClientCredentials();
 credentials.PromptType = CredentialPromptType.PromptIfNeeded;
 credentials.Storage = new VssClientCredentialStorage(storageKind: "VssApp2", storageNamespace: "VisualStudio");
 var aTeamProjects = new TfsTeamProjectCollection(new Uri("https://xxxxx.visualstudio.com/"), credentials);
 aTeamProjects.EnsureAuthenticated();


来源:https://stackoverflow.com/questions/47637033/tf30063-you-are-not-authorized-programmatic-access-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!