-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathInteractiveProviderBehavior.cs
More file actions
63 lines (59 loc) · 2.04 KB
/
InteractiveProviderBehavior.cs
File metadata and controls
63 lines (59 loc) · 2.04 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#if DOTNET
using System;
using System.Linq;
using System.Windows;
using Microsoft.Toolkit.Graph.Providers;
#else
using System.Linq;
using Microsoft.System;
#endif
#if DOTNET
namespace Microsoft.Toolkit.Wpf.Graph.Providers
#else
namespace Microsoft.Toolkit.Graph.Providers
#endif
{
/// <summary>
/// Put in a xaml page with ClientId
/// https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Acquiring-tokens-interactively.
/// </summary>
/// <example>
/// <code>
/// <Interactivity:Interaction.Behaviors>
/// <providers:InteractiveProviderBehavior ClientId = "MyClientIdGuid"/>
/// </Interactivity:Interaction.Behaviors>
/// </code>
/// </example>
public class InteractiveProviderBehavior : CommonProviderBehaviorBase
{
private object lock_sync = new object();
private bool initialized = false;
/// <inheritdoc/>
protected override bool Initialize()
{
lock (lock_sync)
{
if (!initialized)
{
#if DOTNET
_ = Dispatcher.BeginInvoke(new Action(async () =>
{
ProviderManager.Instance.GlobalProvider =
await QuickCreate.CreateMsalProviderAsync(ClientId, RedirectUri, Scopes.ToArray());
}), System.Windows.Threading.DispatcherPriority.Normal);
#else
_ = DispatcherQueue.GetForCurrentThread().TryEnqueue(DispatcherQueuePriority.Normal, async () =>
{
ProviderManager.Instance.GlobalProvider =
await QuickCreate.CreateMsalProviderAsync(ClientId, RedirectUri, Scopes.ToArray());
});
#endif
}
}
return base.Initialize();
}
}
}