Skip to content

Instantly share code, notes, and snippets.

@ctaggart
Created December 28, 2013 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctaggart/8164083 to your computer and use it in GitHub Desktop.
Save ctaggart/8164083 to your computer and use it in GitHub Desktop.
#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()
@ravpacheco
Copy link

Interesting.

One question, what package you downloaded to use "Microsoft.VisualStudio" namespace.
I'm not found this, can you help me ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment