This repository has been archived by the owner on Nov 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
MainPage.xaml.cs
81 lines (65 loc) · 2.64 KB
/
MainPage.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using DropNetRT.Sample.WP8.Resources;
using DropNetRT.Sample.WP8.Extensions;
using DropNetRT.Sample.WP8.ViewModels;
namespace DropNetRT.Sample.WP8
{
public partial class MainPage : PhoneApplicationPage
{
//TODO - Your callback url here
private const string _tokenCallbackUrl = "http://dkdevelopment.net/";
private LoginViewModel _model;
// Constructor
public MainPage()
{
InitializeComponent();
loginBrowser.LoadCompleted += loginBrowser_LoadCompleted;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
//Show the splash screen
MessageBox.Show("Welcome to the DropNet Sample App. This app demonstrates how to authenticate with the Dropbox API through DropNetRT as well as basic API functionality.");
_model = new LoginViewModel(this.GetProgressIndicator(), Dispatcher);
this.DataContext = _model;
}
private async void btnLogin_Click(object sender, System.Windows.RoutedEventArgs e)
{
_model.SetStatus("Loading...", true);
_model.ShowBrowser = true;
//Get the request token
var requestToken = await App.DropNetClient.GetRequestToken();
var tokenUrl = App.DropNetClient.BuildAuthorizeUrl(requestToken, _tokenCallbackUrl);
//Open a browser with the URL
loginBrowser.Navigate(new Uri(tokenUrl));
}
private async void loginBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
//check for the call back url here
if (e.Uri.Host == "dkdevelopment.net")
{
//SUCCESS!
_model.SetStatus("Getting Access Token...", true);
var accessToken = await App.DropNetClient.GetAccessToken();
//TODO - Save this token/Secret for remember me function
//Set the user Token/Secret in the current instance of DropNetClient
App.DropNetClient.SetUserToken(accessToken);
_model.SetStatus("Login successful", false, 5000);
NavigationService.Navigate(new Uri("/ContentsPage.xaml", UriKind.RelativeOrAbsolute));
}
else
{
//Loaded the login page
_model.ClearStatus();
}
}
}
}