This repository has been archived by the owner on May 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
App.xaml.cs
59 lines (49 loc) · 1.73 KB
/
App.xaml.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
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Identity.Client;
using Microsoft.Graph;
using System.Net.Http.Headers;
using Xamarin.Forms;
namespace PhotoSender
{
public partial class App : Application
{
public static PublicClientApplication PCA;
public static string AppId = "[APP_ID_HERE]";
public static string[] AppScopes = { "User.Read", "Mail.Read", "Mail.Send", "Files.ReadWrite", "People.Read" };
public static UIParent AuthUiParent = null;
public static bool PendingAuth = false;
public static GraphServiceClient GraphClient;
public App ()
{
InitializeComponent();
PCA = new PublicClientApplication(AppId);
GraphClient = new GraphServiceClient(new DelegateAuthenticationProvider(
async (request) =>
{
var accounts = await PCA.GetAccountsAsync();
// Get token silently from MSAL
var authResult = await PCA.AcquireTokenSilentAsync(AppScopes, accounts.FirstOrDefault());
// Add the access token to the "Authorization" header
request.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
}
));
MainPage = new SignInPage();
}
protected override void OnStart ()
{
// Handle when your app starts
}
protected override void OnSleep ()
{
// Handle when your app sleeps
}
protected override void OnResume ()
{
// Handle when your app resumes
}
}
}