public async Task <ActionResult> InitiateAdminConsent(ServicePrincipalModel principalModel)
        {
            return(await SafeExecuteView(async() =>
            {
                // Validate the basic input data
                if (string.IsNullOrEmpty(AuthenticationConfig.SessionItems.GraphTargetTenant))
                {
                    throw new Exception("Cannot initate Admin Consent without a default tenant known!");
                }
                else
                {
                    // Start the consent flow for the target tenant
                    var redirectUrl = string.Format("{0}{1}",
                                                    Request.Url.GetLeftPart(UriPartial.Authority),
                                                    Url.Action("CatchConsentResult"));
                    var authorizationUrl = await AuthenticationLogic.ConstructConsentUrlAsync
                                           (
                        AuthenticationConfig.SessionItems.GraphTargetTenant,
                        AuthenticationConfig.ConfiguratinItems.ManagementAppUri,
                        redirectUrl,
                        true
                                           );

                    return Redirect(authorizationUrl);
                }
            }));
        }
        public async Task <ActionResult> InitiateConsent(ServicePrincipalModel principalModel)
        {
            return(await SafeExecuteView(async() =>
            {
                // Validate the basic input data
                if (string.IsNullOrEmpty(principalModel.ConsentAzureAdTenantDomainOrId))
                {
                    ModelState.AddModelError("ConsentAzureAdTenantDomainOrId", "Please enter a Tenant ID (GUID) or a Tenant Domain (e.g. xyz.onmicrosoft.com) for initiaiting the consent!");
                }

                if (ModelState.IsValid)
                {
                    // Start the consent flow for the target tenant
                    var redirectUrl = string.Format("{0}{1}",
                                                    Request.Url.GetLeftPart(UriPartial.Authority),
                                                    Url.Action("CatchConsentResult"));
                    var authorizationUrl = await AuthenticationLogic.ConstructConsentUrlAsync
                                           (
                        principalModel.ConsentAzureAdTenantDomainOrId,
                        AuthenticationConfig.ConfiguratinItems.ManagementAppUri,
                        redirectUrl
                                           );

                    return Redirect(authorizationUrl);
                }
                else
                {
                    principalModel.SubmitConsentEnabled = true;
                    principalModel.SubmitSpEnabled = false;
                    principalModel.SubmitAdminConsentEnabled = false;
                    principalModel.UserMessage = "Please fix errors and try initiating the consent again!";
                    return View("Index", principalModel);
                }
            }));
        }