Skip to content

Commit a3ae144

Browse files
committed
OneDrive for Business bug fixes, updated docs. Cleaned up Sample app for the service
1 parent 7182a2b commit a3ae144

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-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: 34 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 = true;
4951

5052
try
5153
{
@@ -74,34 +76,53 @@ private async Task SigninAsync(int indexProvider, string appClientId)
7476
catch (ServiceException serviceEx)
7577
{
7678
await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(serviceEx);
79+
succeeded = false;
7780
}
7881
catch (Exception ex)
7982
{
8083
await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message);
8184
TrackingManager.TrackException(ex);
85+
succeeded = false;
8286
}
8387
finally
8488
{
8589
Shell.Current.DisplayWaitRing = false;
8690
}
8791

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;
92+
if (succeeded)
93+
{
94+
FilesBox.Visibility = Visibility.Visible;
95+
UserBox.Visibility = Visibility.Visible;
96+
ClientIdBox.Visibility = Visibility.Collapsed;
97+
ClientIdHelper.Visibility = Visibility.Collapsed;
98+
LogOutButton.Visibility = Visibility.Visible;
99+
ConnectButton.Visibility = Visibility.Collapsed;
100+
menuButton.Visibility = Visibility.Visible;
101+
BackButton.Visibility = Visibility.Visible;
102+
}
103+
else
104+
{
105+
FilesBox.Visibility = Visibility.Collapsed;
106+
UserBox.Visibility = Visibility.Collapsed;
107+
ClientIdBox.Visibility = Visibility.Visible;
108+
ClientIdHelper.Visibility = Visibility.Visible;
109+
LogOutButton.Visibility = Visibility.Collapsed;
110+
ConnectButton.Visibility = Visibility.Visible;
111+
menuButton.Visibility = Visibility.Collapsed;
112+
BackButton.Visibility = Visibility.Collapsed;
113+
}
95114
}
96115

97116
private async void ConnectButton_Click(object sender, RoutedEventArgs e)
98117
{
99-
if (string.IsNullOrEmpty(ClientId.Text))
118+
try
100119
{
101-
return;
120+
await SigninAsync(_indexProvider, ClientId.Text);
121+
}
122+
catch (Exception ex)
123+
{
124+
Debug.WriteLine(ex.Message);
102125
}
103-
104-
await SigninAsync(_indexProvider, ClientId.Text);
105126
}
106127

107128
private async void LogOutButton_Click(object sender, RoutedEventArgs e)
@@ -112,6 +133,7 @@ private async void LogOutButton_Click(object sender, RoutedEventArgs e)
112133
LogOutButton.Visibility = Visibility.Collapsed;
113134
UserBox.Visibility = Visibility.Collapsed;
114135
ClientIdBox.Visibility = Visibility.Visible;
136+
ClientIdHelper.Visibility = Visibility.Visible;
115137
ConnectButton.Visibility = Visibility.Visible;
116138
BackButton.Visibility = Visibility.Collapsed;
117139
menuButton.Visibility = Visibility.Collapsed;
@@ -317,7 +339,7 @@ private async void CboProvider_SelectionChanged(object sender, SelectionChangedE
317339
visibility = Visibility.Collapsed;
318340
}
319341

320-
ConnectButton.Visibility = ClientId.Visibility = visibility;
342+
ClientIdHelper.Visibility = ConnectButton.Visibility = ClientId.Visibility = visibility;
321343
}
322344

323345
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".
37+
3738

3839
## Syntax
3940

0 commit comments

Comments
 (0)