public async Task <ActionResult> Authorize()
        {
            ConfidentialClientApplicationBuilder clientBuilder = ConfidentialClientApplicationBuilder.Create(_azureAdOptions.ClientId);

            clientBuilder.WithClientSecret(_azureAdOptions.ClientSecret);
            clientBuilder.WithRedirectUri(LoginRedirectUri.ToString());
            clientBuilder.WithAuthority(_azureAdOptions.Authority);

            ConfidentialClientApplication clientApp = (ConfidentialClientApplication)clientBuilder.Build();

            string[] sassScopes = $"{_azureAdOptions.SaaSScopes}".Split(new[] { ' ' });

            var authResultBuilder = clientApp.AcquireTokenByAuthorizationCode(
                sassScopes,
                HttpContext.Request.Query["code"].ToString()
                );

            try
            {
                var authResult = await authResultBuilder.ExecuteAsync();

                var offer      = Offers.ContosoAppOffer;
                var activation = await _assignedUserService.Activate($"{_azureAdOptions.SaaSAPI}/{offer.OfferID}", authResult.AccessToken);

                ViewBag.Message = JsonConvert.SerializeObject(
                    new { status = "success", activation = activation, accountName = authResult.Account.Username });
            }
            catch (Exception e)
            {
                ViewBag.Message = JsonConvert.SerializeObject(new { status = "failure", error = e.Message });
            }

            return(View());
        }
        public async Task <ActionResult> Authorize()
        {
            ConfidentialClientApplicationBuilder clientBuilder = ConfidentialClientApplicationBuilder.Create(AzureADClientId);

            clientBuilder.WithClientSecret(AzureADClientSecret);
            clientBuilder.WithRedirectUri(loginRedirectUri.ToString());
            clientBuilder.WithAuthority(AzureADAuthority);

            ConfidentialClientApplication clientApp = (ConfidentialClientApplication)clientBuilder.Build();

            string[] sassScopes = $"{SaaSScopes}".Split(new[] { ' ' });
            try
            {
                // Get and save the token.
                var authResultBuilder = clientApp.AcquireTokenByAuthorizationCode(
                    sassScopes,
                    Request.Params["code"]
                    );

                var authResult = await authResultBuilder.ExecuteAsync();

                var activation = await _assignedUserService.Activate($"{SaaSAPI}/{OfferID}", authResult.AccessToken);

                ViewBag.accountName = authResult.Account.Username;
                return(View(activation));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }

            return(View());
        }