c# - TF30063 : You are not authorized to access https://test. visualstudio.com/DefaultCollection

标签 c# tfs-sdk azure-devops

我正在尝试连接到 TFS 并使用以下代码对用户进行身份验证。但我收到错误:

TF30063: You are not authorized to access https://test.visualstudio.com/DefaultCollection.

var netCred = new NetworkCredential("test@live.in", "password");
                var windowsCred = new WindowsCredential(netCred);
                var tfsCred = new TfsClientCredentials(windowsCred);
                tfsCred.AllowInteractive = false;
                var tpc = new TfsTeamProjectCollection(tfsUri, tfsCred);
                tpc.Authenticate();

当我在代码下方运行时,它会提示我必须输入凭据的窗口。

var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://test.visualstudio.com/DefaultCollection"));
            var store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

此应用程序将由外部人员使用,我需要静默登录到 TFS。

我看到了下面的解决方案,但我不能要求每个用户都这样做。

http://blogs.msdn.com/b/buckh/archive/2013/01/07/how-to-connect-to-tf-service-without-a-prompt-for-liveid-credentials.aspx

请给我一些解决方案。

最佳答案

Your users will have to log on using the Live ID/MSA一次,他们可以选中保存凭据的框,这样他们以后就不会收到提示。 future Visual Studio Online 可能会转向使用 Azure Active Diectory/Azure Access Control Services 的解决方案,这将允许您使用其他凭据类型,现在您需要让您的用户启用基本身份验证或让他们进行身份验证到 VSO 一次并让他们选中“保存凭据”复选框,这样他们以后就不会收到提示。

Uri collectionUri = new Uri("https://youraccount.visualstudio.com:443/defaultcollection");
UICredentialsProvider credentialProvider = new UICredentialsProvider();
var tfs = TfsTeamProjectCollectionFactory
               .GetTeamProjectCollection(collectionUri, new UICredentialsProvider());
tfs.EnsureAuthenticated();

如果您想使用 Basic Credentials 进行连接,您还可以使用此代码(在为您要使用的帐户启用 Basic Credentials 之后):

NetworkCredential netCred = new NetworkCredential(
    "someone@yahoo.com",
    "password");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
    new Uri("https://YourAcct.visualstudio.com/DefaultCollection"),
    tfsCred);

tpc.Authenticate();

关于c# - TF30063 : You are not authorized to access https://test. visualstudio.com/DefaultCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22594064/

相关文章:

c# - VS30063 : You are not authorized to access https://dev. 蔚蓝网

git - Azure DevOps - 如何使用多个存储库创建构建管道?

azure - 对于指标警报类型,搜索查询应包含 'AggregatedValue' 和 'bin(timestamp, [roundTo])'

c# - XmlReader - 我需要编辑一个元素并生成一个新元素

c# - 带有热图的wpf bing map应用程序?

api - 找到合并分支的tfs路径

azure-devops - 从 Azure DevOps Pipeline 祖父 Pipeline 下载工件

c# - 核心 2.1 signalR 成功连接但客户端为空

c# - 循环遍历转发器控件中的嵌套集合

c++ - 是否可以使用 C++( native )访问 TFS API