예제 #1
0
 private void ProcessAuth(string responseString)
 {
     this.webBrowser.Visible = false;
     var nvc = HttpUtility.ParseQueryString(responseString);
     string code = nvc["code"];
     TokenResponse tokenResponse = GetAccessToken(code);
     AADUser user = GetAzureADUser(tokenResponse.AccessToken);
     label4.Text = string.Format("Ah! welcome {0}! Registering CloudStack in your Azure Active Directory now ... ", user.DisplayName);
     label4.Visible = true;
     RegisterAzureADApplication(tokenResponse.AccessToken, "http://localhost:55651/");
     labelCheck3.Visible = true;
     label5.Visible = true;
 }
예제 #2
0
        public AADUser GetAzureADUser(string accessToken)
        {
            AADUser user = null;
            string url = string.Format(GraphUrl, "me");

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            request.Headers.Add(HttpRequestHeader.Authorization, string.Format("{0} {1}", "Bearer", accessToken));
            request.UserAgent = "http://www.vipswapper.com/cloudstack";
            WebResponse response = request.GetResponse();
            using (Stream stream = response.GetResponseStream())
            {
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(AADUser));
                user = (AADUser)ser.ReadObject(stream);
            }
            return user;
        }
예제 #3
0
        static void Main(string[] args)
        {
            CloudStackConsoleInstaller installer = new CloudStackConsoleInstaller();

            Console.Write("---------- CloudStack Installer ----------\n");
            Console.Write("Hi there! \nFirst, this installer will download the latest CloudStack binaries." +
                          " \nThen, it will configure a new website for CloudStack on this IIS server. \nFinally, it will register the" +
                          " instance of CloudStack with your Azure Active Directory so that it can manage your Azure cloud.\n\n");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write("Sounds good? If so, hit enter. If not, close this widow.");
            Console.ResetColor();
            Console.ReadLine();
            Console.Write("\n1) Downloading CloudStack binaries ... ");
            installer.DummyMethodDownloadCloudStackBinaries();
            Console.Write("Done. \n\n2) Installing CloudStack website on this web server ... ");
            installer.DummyMethodInstallCloudStackWebsite();
            Console.Write("Done. \n\n3) Alright, let's connect this CloudStack instance with your Azure Cloud - ");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write("please enter the id of your Azure subscription that you wish to connect: ");
            Console.ResetColor();
            string subscriptionId = Console.ReadLine();
            string aadId          = installer.GetAADForSubscription(subscriptionId);
            DeviceAuthCodeResponse codeResponse = installer.GetDeviceAuthCode(aadId);

            Console.Write("Got it. \nNow, you must authenticate with the account that you use to manage your Azure cloud - ");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write("use a web browser to open the page {0} and enter the code {1}.", codeResponse.VerificationUrl, codeResponse.UserCode);
            Console.ResetColor();
            Console.Write("\nPatiently waiting ... ");
            DeviceAuthTokenResponse tokenResponse = installer.GetDeviceAuthToken(codeResponse, aadId);
            AADUser user = installer.GetAzureADUser(tokenResponse.AccessToken);

            Console.Write("Ah! welcome {0}! Registering CloudStack in your Azure Active Directory now ... ", user.DisplayName);
            installer.RegisterAzureADApplication(tokenResponse.AccessToken, "http://localhost");
            Console.Write(" All done.");
        }