Esempio n. 1
0
        public IEnumerable <TeamProjectReference> DeviceCodeADAL(string vstsAccountName, string applicationId)
        {
            Guid tenant = GetAccountTenant(vstsAccountName);
            AuthenticationContext authenticationContext = new AadAuthenticationContext("https://login.windows.net/" + tenant, validateAuthority: true);
            DeviceCodeResult      codeResult            = authenticationContext.AcquireDeviceCodeAsync(VSTSResourceId, applicationId).Result;

            Console.WriteLine("You need to sign in.");
            Console.WriteLine("Message: " + codeResult.Message + "\n");
            AuthenticationResult authenticationResult = authenticationContext.AcquireTokenByDeviceCodeAsync(codeResult).Result;

            VssOAuthAccessTokenCredential oAuthCredential = new VssOAuthAccessTokenCredential(authenticationResult.AccessToken);

            return(ListProjectsViaClientLibrary(vstsAccountName, oAuthCredential));
        }
 static AuthenticationResult GetTokenViaCode(AuthenticationContext ctx)
 {
     AuthenticationResult result = null;
     try
     {
         DeviceCodeResult codeResult = ctx.AcquireDeviceCodeAsync(resource, clientId).Result;
         Console.ResetColor();
         Console.WriteLine("You need to sign in.");
         Console.WriteLine("Message: " + codeResult.Message + "\n");
         result = ctx.AcquireTokenByDeviceCodeAsync(codeResult).Result;
     }
     catch (Exception exc)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Something went wrong.");
         Console.WriteLine("Message: " + exc.Message + "\n");
     }
     return result;
 }