-
Notifications
You must be signed in to change notification settings - Fork 1
/
AuthWebPage.xaml.cs
58 lines (53 loc) · 1.78 KB
/
AuthWebPage.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
using UWStatsUWPLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using static UWStatsUWPLib.SettingsProvider;
namespace UWStats
{
public sealed partial class AuthWebPage : Page
{
public AuthWebPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
authView.Source = (Uri)e.Parameter;
}
private async void authView_NavigationStarting(Microsoft.UI.Xaml.Controls.WebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs args)
{
if (args.Uri.StartsWith("http://localhost:5543/callback"))
{
string code = args.Uri.Split("?code=")[1];
await Auth.GetCallback(code);
if (Auth.isAuthorized)
{
this.Frame.Navigate(typeof(InterfacePage), AccessToken);
}
else
{
ContentDialog dialog = new ContentDialog();
dialog.Title = "Error";
dialog.Content = "We couldn't authenticate you.";
dialog.PrimaryButtonText = "OK";
dialog.PrimaryButtonCommand = null;
await dialog.ShowAsync();
}
}
}
}
}