-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathHomeController.cs
More file actions
48 lines (43 loc) · 1.5 KB
/
HomeController.cs
File metadata and controls
48 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ASPNET_File_Picker.Models;
using Microsoft.Graph;
using System.Net.Http.Headers;
namespace ASPNET_File_Picker.Controllers
{
public class HomeController : Controller
{
[HttpGet]
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<String> Index(SelectedFileViewModel model)
{
var graphClient = GetAuthenticatedClient(model.AccessToken);
var result = await graphClient.Drives[model.DriveId].Items[model.FileId].Request().Expand("thumbnails").GetAsync();
return result.Thumbnails.First().Large.Url;
}
/// <summary>
/// Gets a new istance of <see cref="GraphServiceClient"/>
/// </summary>
/// <returns></returns>
private GraphServiceClient GetAuthenticatedClient(string accessToken)
{
// Create Microsoft Graph client.
return new GraphServiceClient(
"https://graph.microsoft.com/v1.0",
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
// Set bearer authentication on header
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
}));
}
}
}