public ActionResult Share(string id)
        {
            // Values Needed for the People Picker
            ViewData["tenant"] = ConfigHelper.Tenant;
            ViewData["token"]  = GraphHelper.AcquireToken(ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value);

            // Get the task details
            WebAppGroupClaimsDotNet.Models.Task task = TasksDbHelper.GetTask(Convert.ToInt32(id));
            if (task == null)
            {
                RedirectToAction("ShowError", "Error", new { message = "Task Not Found in DB." });
            }
            ViewData["shares"]   = task.SharedWith.ToList();
            ViewData["taskText"] = task.TaskText;
            ViewData["taskId"]   = task.TaskID;
            ViewData["userId"]   = ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value;
            return(View());
        }
コード例 #2
0
        public async Task <ActionResult> Search(string query)
        {
            // Instead of making Graph API CORS requests from javascript directly,
            // here we proxy the calls from the server.  This saves us from having to share
            // access tokens with the client code.

            if (HttpContext.Request.IsAjaxRequest())
            {
                try
                {
                    // Get a token from the ADAL cache
                    string token = GraphHelper.AcquireToken(ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value);

                    // Send the Graph API query
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, query);
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    HttpResponseMessage response = await client.SendAsync(request);

                    // Return the JSON from the Graph API directly to the client
                    if (response.IsSuccessStatusCode)
                    {
                        string responseString = await response.Content.ReadAsStringAsync();

                        return(Content(responseString, "application/json"));
                    }
                    else
                    {
                        return(new HttpStatusCodeResult(response.StatusCode));
                    }
                }
                catch (AdalException ex)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
                }
            }

            return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
        }
コード例 #3
0
        public async Task <ActionResult> Search(string query)
        {
            if (HttpContext.Request.IsAjaxRequest())
            {
                string             token   = GraphHelper.AcquireToken(ClaimsPrincipal.Current.FindFirst(Globals.ObjectIdClaimType).Value);
                HttpClient         client  = new HttpClient();
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, query);
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
                HttpResponseMessage response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    string responseString = await response.Content.ReadAsStringAsync();

                    return(Content(responseString, "application/json"));
                }
                else
                {
                    return(new HttpStatusCodeResult(response.StatusCode));
                }
            }

            return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
        }