使用非个性化进行身份验证 (Team Foundation Server)
Authenticating (Team Foundation Server) with impersonalization
我找到了如何使用给定的 username/password 从我的应用程序向 TFS 进行身份验证。
我想使用 REST 服务。
public static void BasicAuthRestSample()
{
// Create instance of VssConnection using basic auth credentials.
// For security, ensure you are connecting to an https server, since credentials get sent in plain text.
VssConnection connection = new VssConnection(new Uri(collectionUri), new VssCredentials(new WindowsCredential(new NetworkCredential(username, password))));
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();
List<QueryHierarchyItem> items = witClient.GetQueriesAsync(teamProjectName).Result;
}
这个解决方案工作正常,但如果我创建一个新的工作项,它是由 "username" 创建的。
但是我想通过非个性化用户创建工作项,所以如果我在 TFS 中查看工作项,我希望看到 "seconduser" 作为创建者。
我在谷歌上搜索了很多但找不到示例....
VSTS 更新:
在尝试实施后我发现了这个:
"For security reasons (and compliance and a number of other reasons), the impersonation header isn't supported on Visual Studio Online"
奇怪的是,错误消息目前具有误导性,它告诉我我需要特殊权限,而整个模拟功能实际上在 VSTS 中被禁用。
你应该使用 TfsTeamProjectCollection
constructor accepting an IdentityDescriptor
。
您可以在 Introducing TFS Impersonation.
中找到完整的解释
来自 post 的片段
// Get the TFS Identity Management Service
IIdentityManagementService identityManagementService =
currentUserCollection.GetService<IIdentityManagementService>();
// Look up the user that we want to impersonate
TeamFoundationIdentity identity = identityManagementService.ReadIdentity(
IdentitySearchFactor.AccountName, username, MembershipQuery.None, ReadIdentityOptions.None);
TfsTeamProjectCollection impersonatedCollection =
new TfsTeamProjectCollection(currentUserCollection.Uri, identity.Descriptor);
根据 REST API Reference for VS Team Services and TFS,目前没有类似于 TFS 模拟的 REST API。由于 .net api 仍然适用于 VSTS 的大多数功能(不支持 vNext 构建等),您可以将 .net api 作为替代方案。
我找到了如何使用给定的 username/password 从我的应用程序向 TFS 进行身份验证。 我想使用 REST 服务。
public static void BasicAuthRestSample()
{
// Create instance of VssConnection using basic auth credentials.
// For security, ensure you are connecting to an https server, since credentials get sent in plain text.
VssConnection connection = new VssConnection(new Uri(collectionUri), new VssCredentials(new WindowsCredential(new NetworkCredential(username, password))));
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();
List<QueryHierarchyItem> items = witClient.GetQueriesAsync(teamProjectName).Result;
}
这个解决方案工作正常,但如果我创建一个新的工作项,它是由 "username" 创建的。 但是我想通过非个性化用户创建工作项,所以如果我在 TFS 中查看工作项,我希望看到 "seconduser" 作为创建者。
我在谷歌上搜索了很多但找不到示例....
VSTS 更新:
在尝试实施后我发现了这个:
"For security reasons (and compliance and a number of other reasons), the impersonation header isn't supported on Visual Studio Online"
奇怪的是,错误消息目前具有误导性,它告诉我我需要特殊权限,而整个模拟功能实际上在 VSTS 中被禁用。
你应该使用 TfsTeamProjectCollection
constructor accepting an IdentityDescriptor
。
您可以在 Introducing TFS Impersonation.
来自 post 的片段
// Get the TFS Identity Management Service
IIdentityManagementService identityManagementService =
currentUserCollection.GetService<IIdentityManagementService>();
// Look up the user that we want to impersonate
TeamFoundationIdentity identity = identityManagementService.ReadIdentity(
IdentitySearchFactor.AccountName, username, MembershipQuery.None, ReadIdentityOptions.None);
TfsTeamProjectCollection impersonatedCollection =
new TfsTeamProjectCollection(currentUserCollection.Uri, identity.Descriptor);
根据 REST API Reference for VS Team Services and TFS,目前没有类似于 TFS 模拟的 REST API。由于 .net api 仍然适用于 VSTS 的大多数功能(不支持 vNext 构建等),您可以将 .net api 作为替代方案。