Пример #1
0
        public async Task <IActionResult> Workflows()
        {
            AuthenticationResult result = null;

            try
            {
                // Because we signed-in already in the WebApp, the userObjectId is know
                string userObjectID = (User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier"))?.Value;

                // Using ADAL.Net, get a bearer token to access the WorkbenchListService
                AuthenticationContext authContext = new AuthenticationContext(AzureAdOptions.Settings.Authority, new NaiveSessionCache(userObjectID, HttpContext.Session));
                ClientCredential      credential  = new ClientCredential(AzureAdOptions.Settings.ClientId, AzureAdOptions.Settings.ClientSecret);
                result = await authContext.AcquireTokenSilentAsync(AzureAdOptions.Settings.WorkbenchResourceId, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));

                .
                HttpClient         client  = new HttpClient();
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, AzureAdOptions.Settings.WorkbenchBaseAddress + "/api/v1/applications/1/workflows");
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
                HttpResponseMessage response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    JsonSerializerSettings settings = new JsonSerializerSettings();
                    String json_string = await response.Content.ReadAsStringAsync();

                    WorkflowReturnType workflowResponse = JsonConvert.DeserializeObject <WorkflowReturnType>(json_string);

                    List <IQC_WebClient_Workbench.Models.Workflow> workflows = workflowResponse.Workflows;


                    return(View(workflows));
                }
                else
                {
                    var x = 0;
                }
            }
Пример #2
0
        public async Task <IActionResult> Workflows()
        {
            AuthenticationResult result = null;

            try
            {
                // Because we signed-in already in the WebApp, the userObjectId is know
                string userObjectID = (User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier"))?.Value;

                // Using ADAL.Net, get a bearer token to access the WorkbenchListService
                AuthenticationContext authContext = new AuthenticationContext(AzureAdOptions.Settings.Authority,
                                                                              new NaiveSessionCache(userObjectID, HttpContext.Session));
                ClientCredential credential = new ClientCredential(AzureAdOptions.Settings.ClientId,
                                                                   AzureAdOptions.Settings.ClientSecret);

                result = await authContext.AcquireTokenSilentAsync(AzureAdOptions.Settings.WorkbenchResourceId, credential,
                                                                   new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));

                HttpClient         client  = new HttpClient();
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
                                                                    AzureAdOptions.Settings.WorkbenchBaseAddress + "/api/v1/applications/1/workflows");
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
                HttpResponseMessage response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    JsonSerializerSettings settings = new JsonSerializerSettings();
                    String json_string = await response.Content.ReadAsStringAsync();

                    WorkflowReturnType workflowResponse = JsonConvert.DeserializeObject <WorkflowReturnType>(json_string);

                    List <IQC_WebClient_Workbench.Models.Workflow> workflows = workflowResponse.Workflows;


                    return(View(workflows));
                }
                else
                {
                    var x = 0;
                }
            }
            catch (Exception ee)
            {
                if (HttpContext.Request.Query["reauth"] == "True" || ee.Message.ToLower().Contains("silently"))
                {
                    //
                    // Send an OpenID Connect sign-in request to get a new set of tokens.
                    // If the user still has a valid session with Azure AD, they will not be prompted for their credentials.
                    // The OpenID Connect middleware will return to this controller after the sign-in response has been handled.
                    //
                    return(new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme));
                }

                return(View(new List <IQC_WebClient_Workbench.Models.Workflow>()
                {
                    new IQC_WebClient_Workbench.Models.Workflow()
                    {
                        Name = ee.InnerException.Message
                    }
                }));
            }

            return(View(new List <IQC_WebClient_Workbench.Models.Workflow>()
            {
                new IQC_WebClient_Workbench.Models.Workflow()
                {
                    Name = "Error"
                }
            }));
        }