How to get Visual Studio Online credentials in the cache in the registry?

When you log into Visual Studio 2013, it caches your profile and registry credentials:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\ConnectedUser\IdeUser\Cache
HKEY_CURRENT_USER\Software\Microsoft\VSCommon\12.0\ClientServices\TokenStorage\VisualStudio\IdeUser

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

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

use tfs = new TfsTeamProjectCollection(Uri "https://ctaggart.visualstudio.com/DefaultCollection")
tfs.Authenticate()

How to use these values ​​in C # or F # using Visual Studio or TFS APIs?

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

I don't know 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")

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

Process monitor of code

+2
1

. Microsoft.TeamFoundation.Client.TfsClientCredentialStorage , . F # script . :

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

All Articles