Skip to content

Commit ffc8a92

Browse files
authored
Merge pull request #879 from Microsoft/cbarker/onedrivefixes
OneDrive for Business bug fixes, updated docs. Cleaned up Sample app …
2 parents 6704a56 + ade3756 commit ffc8a92

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/OneDrive Service/OneDriveCode.bind

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// OneDrive For Business you need to register your app from the Azure Management Portal
1919
// For more information to manualy register your app see go to the following article
2020
// https://docs.microsoft.com/en-US/azure/active-directory/develop/active-directory-authentication-scenarios#basics-of-registering-an-application-in-azure-ad
21-
// When registering your application don't forget to add the Office 365 Sharepoint Online application with the "Read and Write user Files" permissions
21+
// When registering your application don't forget to add the Office 365 Sharepoint Online application with the "Read and Write user Files" permissions. You should set your Redirect URI to "urn:ietf:wg:oauth:2.0:oob". You may also need to add the following capabilities to your Package.appxmanifest: privateNetworkClientServer; enterpriseAuthentication
2222

2323
// First get the root of your OneDrive
2424
// By default the service silently connects the current Windows user if Windows is associated with a Microsoft Account

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/OneDrive Service/OneDrivePage.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@
411411
x:Name="ClientId"
412412
Margin="0,15,0,12"
413413
Text="" Visibility="Collapsed"/>
414+
<HyperlinkButton x:Name="ClientIdHelper" Margin="0,0,0,15"
415+
Content="Show me how to get this ID"
416+
NavigateUri="https://dev.onedrive.com/app-registration.htm"
417+
Visibility="Collapsed"
418+
/>
414419
<Button Content="Sign in"
415420
x:Name="ConnectButton"
416421
Click="ConnectButton_Click"

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/OneDrive Service/OneDrivePage.xaml.cs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// ******************************************************************
1212

1313
using System;
14+
using System.Diagnostics;
1415
using System.Threading.Tasks;
1516
using Microsoft.Graph;
1617
using Microsoft.Toolkit.Uwp.Services.OneDrive;
@@ -46,6 +47,7 @@ private async Task SigninAsync(int indexProvider, string appClientId)
4647
}
4748

4849
Shell.Current.DisplayWaitRing = true;
50+
bool succeeded = false;
4951

5052
try
5153
{
@@ -70,6 +72,7 @@ private async Task SigninAsync(int indexProvider, string appClientId)
7072

7173
_currentFolder = _rootFolder = await OneDriveService.Instance.RootFolderAsync();
7274
OneDriveItemsList.ItemsSource = _rootFolder.GetItemsAsync();
75+
succeeded = true;
7376
}
7477
catch (ServiceException serviceEx)
7578
{
@@ -85,23 +88,40 @@ private async Task SigninAsync(int indexProvider, string appClientId)
8588
Shell.Current.DisplayWaitRing = false;
8689
}
8790

88-
FilesBox.Visibility = Visibility.Visible;
89-
UserBox.Visibility = Visibility.Visible;
90-
ClientIdBox.Visibility = Visibility.Collapsed;
91-
LogOutButton.Visibility = Visibility.Visible;
92-
ConnectButton.Visibility = Visibility.Collapsed;
93-
menuButton.Visibility = Visibility.Visible;
94-
BackButton.Visibility = Visibility.Visible;
91+
if (succeeded)
92+
{
93+
FilesBox.Visibility = Visibility.Visible;
94+
UserBox.Visibility = Visibility.Visible;
95+
ClientIdBox.Visibility = Visibility.Collapsed;
96+
ClientIdHelper.Visibility = Visibility.Collapsed;
97+
LogOutButton.Visibility = Visibility.Visible;
98+
ConnectButton.Visibility = Visibility.Collapsed;
99+
menuButton.Visibility = Visibility.Visible;
100+
BackButton.Visibility = Visibility.Visible;
101+
}
102+
else
103+
{
104+
FilesBox.Visibility = Visibility.Collapsed;
105+
UserBox.Visibility = Visibility.Collapsed;
106+
ClientIdBox.Visibility = Visibility.Visible;
107+
ClientIdHelper.Visibility = Visibility.Visible;
108+
LogOutButton.Visibility = Visibility.Collapsed;
109+
ConnectButton.Visibility = Visibility.Visible;
110+
menuButton.Visibility = Visibility.Collapsed;
111+
BackButton.Visibility = Visibility.Collapsed;
112+
}
95113
}
96114

97115
private async void ConnectButton_Click(object sender, RoutedEventArgs e)
98116
{
99-
if (string.IsNullOrEmpty(ClientId.Text))
117+
try
100118
{
101-
return;
119+
await SigninAsync(_indexProvider, ClientId.Text);
120+
}
121+
catch (Exception ex)
122+
{
123+
await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message);
102124
}
103-
104-
await SigninAsync(_indexProvider, ClientId.Text);
105125
}
106126

107127
private async void LogOutButton_Click(object sender, RoutedEventArgs e)
@@ -112,6 +132,7 @@ private async void LogOutButton_Click(object sender, RoutedEventArgs e)
112132
LogOutButton.Visibility = Visibility.Collapsed;
113133
UserBox.Visibility = Visibility.Collapsed;
114134
ClientIdBox.Visibility = Visibility.Visible;
135+
ClientIdHelper.Visibility = Visibility.Visible;
115136
ConnectButton.Visibility = Visibility.Visible;
116137
BackButton.Visibility = Visibility.Collapsed;
117138
menuButton.Visibility = Visibility.Collapsed;
@@ -317,7 +338,7 @@ private async void CboProvider_SelectionChanged(object sender, SelectionChangedE
317338
visibility = Visibility.Collapsed;
318339
}
319340

320-
ConnectButton.Visibility = ClientId.Visibility = visibility;
341+
ClientIdHelper.Visibility = ConnectButton.Visibility = ClientId.Visibility = visibility;
321342
}
322343

323344
private async void CopyToButton_Click(object sender, RoutedEventArgs e)

Microsoft.Toolkit.Uwp.Services/Services/OneDrive/OneDriveAuthenticationHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ internal static IAuthenticationProvider CreateAdalAuthenticationProvider(string
119119
{
120120
var discoveryResourceUri = "https://api.office.com/discovery/";
121121
_appClientId = appClientId;
122-
IdentityModel.Clients.ActiveDirectory.AuthenticationResult userAuthnResult = await _azureAdContext.AcquireTokenAsync(discoveryResourceUri, appClientId, new Uri(DefaultRedirectUri), new IdentityModel.Clients.ActiveDirectory.PlatformParameters(PromptBehavior.Always, false));
122+
IdentityModel.Clients.ActiveDirectory.AuthenticationResult userAuthnResult = await _azureAdContext.AcquireTokenAsync(discoveryResourceUri, appClientId, new Uri(DefaultRedirectUri), new IdentityModel.Clients.ActiveDirectory.PlatformParameters(PromptBehavior.Auto, true));
123123
_userInfoSettings = SaveUserInfo(userAuthnResult);
124124
return userAuthnResult;
125125
}

docs/services/OneDrive.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ OneDrive for Business requires you to register your app in the Azure Management
3333
OneDrive For Business you need to register your app from the Azure Management Portal
3434
For more information to manualy register your app see go to the following article
3535
https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-scenarios#basics-of-registering-an-application-in-azure-ad
36-
When registering your application don't forget to add the Office 365 Sharepoint Online application with the "Read and Write user Files" permissions
36+
When registering your application don't forget to add the Office 365 Sharepoint Online application with the "Read and Write user Files" permissions. You should set your Redirect URI to "urn:ietf:wg:oauth:2.0:oob". You may also need to add the following capabilities to your Package.appxmanifest: privateNetworkClientServer; enterpriseAuthentication
37+
3738

3839
## Syntax
3940

0 commit comments

Comments
 (0)