This repository was archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAuthManager.cs
More file actions
47 lines (39 loc) · 1.45 KB
/
AuthManager.cs
File metadata and controls
47 lines (39 loc) · 1.45 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
using Microsoft.Live;
using System;
using System.Threading.Tasks;
namespace AutoCADNote
{
public class AuthManager
{
private static readonly string ClientId = "ENTER_YOUR_MICROSOFT_LIVE_APPLICATION_CLIENT_ID";
// Define the permission scopes
private static readonly string[] scopes = new string[] { "wl.signin", "wl.offline_access", "office.onenote_update_by_app" };
// Set up the Live variables
private static LiveAuthClient authClient;
public static string Token { get; private set; }
public static string Code { get; private set; }
internal static async Task<string> GetLoginUrl()
{
// Create authClient
if (authClient == null)
{
await Initialize();
}
// Get the login url with the right scopes
return authClient.GetLoginUrl(scopes);
}
private static async Task Initialize()
{
authClient = new LiveAuthClient(ClientId);
LiveLoginResult loginResult = await authClient.InitializeAsync(scopes);
}
internal static async Task<string> GetToken(Uri url)
{
// store the token and the code
Code = url.Query.Split('&', '=')[1];
var session = await authClient.ExchangeAuthCodeAsync(Code);
Token = session.AccessToken;
return Token;
}
}
}