如何获取注册表中缓存的Visual Studio Online凭据? [英] How do I get the Visual Studio Online credentials cached in the registry?

查看:165
本文介绍了如何获取注册表中缓存的Visual Studio Online凭据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

登录Visual Studio 2013时,它会将您的配置文件和凭据缓存在注册表中:

When you sign into Visual Studio 2013, it caches your profile and credentials in the registry:

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进行身份验证时,它将凭据复制到:

When you authenticate with Visual Studio Online using the TFS API, it then copies the credentials to:

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#中使用这些值?

How do I use these values in C# or F# using the Visual Studio or TFS APIs?

我已经收集到Vss可能表示Visual Studio服务.有一个Microsoft.VisualStudio.Services.Common. CredentialsCacheManager 和Microsoft.TeamFoundation.Client中的另一个,但是我不确定如何使用两者.它具有一个ContainCredentials,GetCredentials和DeleteCredentials,因此看起来很有希望. GetCredentials返回 TfsCredentialCacheEntry ,它具有Credentials属性来获取System.Net.NetworkCredential,而这正是我在寻找的东西.

I've gathered that Vss may mean Visual Studio Services. There is a Microsoft.VisualStudio.Services.Common.CredentialsCacheManager and another in Microsoft.TeamFoundation.Client, but I'm not sure how to use either. It has a ContainCredentials, GetCredentials, and DeleteCredentials, so it looks promising. The GetCredentials returns a TfsCredentialCacheEntry, which has a Credentials property to get the System.Net.NetworkCredential which is exactly what I'm looking for.

我不知道如何使用CredentialsCacheManager,但这是我尝试过的方法.

I have no idea how to use CredentialsCacheManager, but here is what I tried.

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不是我想要的,或者我不知道如何使用它:

Using Process Monitor, it shows that CredentialsCacheManager is either not what I'm looking for or I don't know how to use it:

推荐答案

我知道了. Microsoft.TeamFoundation.Client.TfsClientCredentialStorage具有我想要的东西.我将所有示例代码作为要点放在了F#脚本中.我也会在这里复制它:

I figured it out. The Microsoft.TeamFoundation.Client.TfsClientCredentialStorage has what I'm looking for. I put all the example code in a F# script as a gist. I'll copy it here as well:

#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()

这篇关于如何获取注册表中缓存的Visual Studio Online凭据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆