登录Visual Studio 2013时,它会将您的配置文件和凭据缓存在注册表中:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\ConnectedUser\IdeUser\Cache
HKEY_CURRENT_USER\Software\Microsoft\VSCommon\12.0\ClientServices\TokenStorage\VisualStudio\IdeUser
使用TFS API向Visual Studio Online进行身份验证时,它将凭据复制到:
HKEY_CURRENT_USER\Software\Microsoft\VSCommon\12.0\ClientServices\TokenStorage\VisualStudio\VssApp
use tfs = new TfsTeamProjectCollection(Uri "https://ctaggart.visualstudio.com/DefaultCollection")
tfs.Authenticate()
如何使用Visual Studio或TFS API在C#或F#中使用这些值?
我已经收集到Vss可能意味着Visual Studio Services。有一个Microsoft.VisualStudio.Services.Common。CredentialsCacheManager和Microsoft.TeamFoundation.Client中的另一个,但我不确定如何使用两者。它具有一个ContainCredentials,GetCredentials和DeleteCredentials,因此看起来很有希望。GetCredentials返回一个TfsCredentialCacheEntry,它具有Credentials属性来获取System.Net.NetworkCredential,这正是我要寻找的。
我不知道如何使用CredentialsCacheManager,但这是我尝试的方法。
let ccm = Microsoft.TeamFoundation.Client.CredentialsCacheManager(@"Software\Microsoft\VSCommon\12.0\ClientServices\TokenStorage\VisualStudio", false)
ccm.ContainsCredentials("IdeUser", Uri "ideuser:https://app.vssps.visualstudio.com:vssuser:federated")
使用Process Monitor,它表明CredentialsCacheManager不是我想要的,或者我不知道如何使用它:
我想到了。Microsoft.TeamFoundation.Client.TfsClientCredentialStorage具有我要的东西。我将所有示例代码都按照要点放在F#脚本中。我也会在这里复制它:
#r "Microsoft.TeamFoundation.Client"
#r "Microsoft.VisualStudio.Services.Common"
#r "System.Net.Http"
open System
open Microsoft.TeamFoundation.Client
// retrieve VssToken
// for the logged in user "IdeUser"
let vssTokenIdeUser = TfsClientCredentialStorage.RetrieveConnectedUserToken()
let tokenStorage = Microsoft.VisualStudio.Services.Common.TokenStorage.VssTokenStorageFactory.GetTokenStorageNamespace "VisualStudio"
let vssTokens = tokenStorage.RetrieveAll "VssApp" |> Array.ofSeq
for t in vssTokens do
printfn "%s %s %s %s" t.Resource t.Type (t.GetProperty "UserId") (t.GetProperty "UserName")
// create a TfsClientCredentials by retrieving an IssuedToken
let ccs = TfsClientCredentialStorage()
let ct = ccs.RetrieveToken(Uri "https://ctaggart.visualstudio.com", Microsoft.VisualStudio.Services.Common.VssCredentialsType.Federated) :?> CookieToken
let cc = CookieCredential(false, ct)
let tcc = TfsClientCredentials cc
// use the TfsClientCredentials to authenticate with
let tfs = new TfsTeamProjectCollection(Uri "https://ctaggart.visualstudio.com/DefaultCollection", tcc)
tfs.Authenticate()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句