-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhotoSorterFactory.cs
49 lines (42 loc) · 1.85 KB
/
PhotoSorterFactory.cs
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
49
using System;
using System.Threading.Tasks;
using ErichMusick.Tools.OneDrive.PhotoSorter.Controllers;
using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
using Newtonsoft.Json;
namespace ErichMusick.Tools.OneDrive.PhotoSorter
{
static class PhotoSorterFactory
{
internal static async Task<PhotoSorter> Create(bool runSampleRequest = false)
{
var config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");
string[] scopes = new string[]
{
"https://graph.microsoft.com/files.readwrite"
};
IPublicClientApplication PublicClientApp;
PublicClientApp = PublicClientApplicationBuilder.Create(config.ClientId)
.WithRedirectUri("http://localhost")
.WithAuthority(AzureCloudInstance.AzurePublic, config.Tenant)
.Build();
InteractiveAuthenticationProvider authenticationProvider = new InteractiveAuthenticationProvider(PublicClientApp, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(authenticationProvider);
// Verify
if (runSampleRequest)
{
var me = await graphServiceClient.Me.Request().WithForceRefresh(true).GetAsync();
Console.WriteLine("Me==>");
Console.WriteLine(JsonConvert.SerializeObject(me));
Console.WriteLine("<==");
var drive = await graphServiceClient.Me.Drive.Root.Request().WithForceRefresh(true).GetAsync();
Console.WriteLine("Drive==>");
Console.WriteLine(JsonConvert.SerializeObject(drive));
Console.WriteLine("<==");
}
var controller = new ItemsController(graphServiceClient);
return new PhotoSorter(controller);
}
}
}