Skip to content

Commit 753832d

Browse files
committed
Merge branch 'master' into rel/2.2.0
2 parents b8cf69d + 77ea3ef commit 753832d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public class OneDriveService : Toolkit.Services.OneDrive.OneDriveService
4545
/// </summary>
4646
private static Toolkit.Services.OneDrive.OneDriveService _graphInstance;
4747

48+
/// <summary>
49+
/// Private field for OnlineIdAuthenticationProvider.PromptType.
50+
/// </summary>
51+
private OnlineIdAuthenticationProvider.PromptType _onlineIdPromptType = OnlineIdAuthenticationProvider.PromptType.PromptIfNeeded;
52+
4853
/// <summary>
4954
/// Gets public singleton property - new version that depends on Graph service / SDK - only supports ADAL v2 endpoint.
5055
/// </summary>
@@ -93,14 +98,28 @@ public static Toolkit.Services.OneDrive.OneDriveService GraphInstance
9398
}
9499
}
95100

101+
/// <summary>
102+
/// Initialize OneDrive Service only for OnlineId Provider
103+
/// </summary>
104+
/// <param name="onlineIdPromptType">Specify whether to prompt for credentials. Set to DoNotPrompt if calling from a background task.</param>
105+
/// <returns>Success or failure</returns>
106+
public bool Initialize(OnlineIdAuthenticationProvider.PromptType onlineIdPromptType)
107+
{
108+
OneDriveScopes scopes = OneDriveScopes.ReadWrite | OneDriveScopes.OfflineAccess;
109+
_onlineIdPromptType = onlineIdPromptType;
110+
return Initialize(scopes, _onlineIdPromptType);
111+
}
112+
96113
/// <summary>
97114
/// Initialize OneDrive Service only for OnlineId Provider
98115
/// </summary>
99116
/// <param name="scopes">Scopes represent various permission levels that an app can request from a user</param>
117+
/// <param name="onlineIdPromptType">Specify whether to prompt for credentials. Set to DoNotPrompt if calling from a background task.</param>
100118
/// <returns>Success or failure</returns>
101-
public bool Initialize(OneDriveScopes scopes = OneDriveScopes.ReadWrite | OneDriveScopes.OfflineAccess)
119+
public bool Initialize(OneDriveScopes scopes = OneDriveScopes.ReadWrite | OneDriveScopes.OfflineAccess, OnlineIdAuthenticationProvider.PromptType onlineIdPromptType = OnlineIdAuthenticationProvider.PromptType.PromptIfNeeded)
102120
{
103-
return Initialize(null, AccountProviderType.OnlineId, scopes);
121+
_onlineIdPromptType = onlineIdPromptType;
122+
return Initialize(null, AccountProviderType.OnlineId, scopes, _onlineIdPromptType);
104123
}
105124

106125
/// <summary>
@@ -112,10 +131,13 @@ public bool Initialize(OneDriveScopes scopes = OneDriveScopes.ReadWrite | OneDri
112131
/// <para>AccountProviderType.Msa: Authenticate the user with a Microsoft Account. You need to register your app https://apps.dev.microsoft.com in the SDK Live section</para>
113132
/// <para>AccountProviderType.Adal: Authenticate the user with a Office 365 Account. You need to register your in Azure Active Directory</para></param>
114133
/// <param name="scopes">Scopes represent various permission levels that an app can request from a user. Could be null if AccountProviderType.Adal is used </param>
134+
/// <param name="onlineIdPromptType">Specify whether to prompt for credentials. Set to DoNotPrompt if calling from a background task.</param>
115135
/// <remarks>If AccountProvider</remarks>
116136
/// <returns>Success or failure.</returns>
117-
public bool Initialize(string appClientId, AccountProviderType accountProviderType = AccountProviderType.OnlineId, OneDriveScopes scopes = OneDriveScopes.ReadWrite | OneDriveScopes.OfflineAccess)
137+
public bool Initialize(string appClientId, AccountProviderType accountProviderType = AccountProviderType.OnlineId, OneDriveScopes scopes = OneDriveScopes.ReadWrite | OneDriveScopes.OfflineAccess, OnlineIdAuthenticationProvider.PromptType onlineIdPromptType = OnlineIdAuthenticationProvider.PromptType.PromptIfNeeded)
118138
{
139+
_onlineIdPromptType = onlineIdPromptType;
140+
119141
if (accountProviderType != AccountProviderType.OnlineId && string.IsNullOrEmpty(appClientId))
120142
{
121143
throw new ArgumentNullException(nameof(appClientId));
@@ -204,7 +226,7 @@ public override async Task<bool> LoginAsync()
204226
else if (_accountProviderType == AccountProviderType.OnlineId)
205227
{
206228
OneDriveAuthenticationHelper.ResourceUri = "https://api.onedrive.com/v1.0";
207-
_accountProvider = new OnlineIdAuthenticationProvider(Scopes);
229+
_accountProvider = new OnlineIdAuthenticationProvider(Scopes, _onlineIdPromptType);
208230
await ((MsaAuthenticationProvider)_accountProvider).RestoreMostRecentFromCacheOrAuthenticateUserAsync();
209231
resourceEndpointUri = OneDriveAuthenticationHelper.ResourceUri;
210232
}

docs/services/OneDrive.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ var folder = await OneDriveService.Instance.RootFolderAsync();
7575

7676
```csharp
7777

78+
// if Windows is associated with a Microsoft account, and your project is associated with the Store then you may use OnlineId for seamless login. If you are doing this and initializing from a background task, then you need to explictly request that no credentials prompt be displayed.
79+
OneDriveService.Instance.Initialize(Microsoft.OneDrive.Sdk.OnlineIdAuthenticationProvider.PromptType.DoNotPrompt);
80+
7881
// if Windows is not associated with a Microsoft Account, you need to initialize the service using an authentication provider AccountProviderType.Msa or AccountProviderType.Adal
7982
OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Msa, OneDriveScopes.OfflineAccess | OneDriveScopes.ReadWrite);
8083

0 commit comments

Comments
 (0)