public async Task GetAuthenticatedClientAsync_AppIdRequired() { bool exceptionThrown = false; try { var client = await BusinessClientExtensions.GetAuthenticatedClientAsync( new AppConfig { ActiveDirectoryReturnUrl = "https://return" }, /* userId */ null, this.credentialCache, this.httpProvider); } catch (OneDriveException exception) { Assert.AreEqual(OneDriveErrorCode.AuthenticationFailure.ToString(), exception.Error.Code, "Unexpected error thrown."); Assert.AreEqual("ActiveDirectoryAppId is required for authentication.", exception.Error.Message, "Unexpected error thrown."); exceptionThrown = true; } Assert.IsTrue(exceptionThrown, "Expected exception not thrown."); }
public async Task GetAuthenticatedClientAsync_ReturnUrlRequired() { try { var client = await BusinessClientExtensions.GetAuthenticatedClientAsync( new BusinessAppConfig(), /* userId */ null, this.credentialCache.Object, this.httpProvider.Object); } catch (OneDriveException exception) { Assert.AreEqual(OneDriveErrorCode.AuthenticationFailure.ToString(), exception.Error.Code, "Unexpected error thrown."); Assert.AreEqual("ActiveDirectoryReturnUrl is required for authenticating a business client.", exception.Error.Message, "Unexpected error thrown."); throw; } }
private async void InitializeClient(ClientType clientType, RoutedEventArgs e) { if (((App)Application.Current).OneDriveClient == null) { OneDriveClient client = null; try { if (clientType == ClientType.Consumer) { client = OneDriveClientExtensions.GetUniversalClient(this.scopes) as OneDriveClient; await client.AuthenticateAsync(); } else { client = await BusinessClientExtensions.GetAuthenticatedClientAsync( new AppConfig { ActiveDirectoryAppId = oneDriveForBusinessClientId, ActiveDirectoryReturnUrl = oneDriveForBusinessReturnUrl, }) as OneDriveClient; } ((App)Application.Current).OneDriveClient = client; ((App)Application.Current).NavigationStack.Add(new ItemModel(new Item())); Frame.Navigate(typeof(MainPage), e); } catch (OneDriveException exception) { // Swallow the auth exception but write message for debugging. Debug.WriteLine(exception.Error.Message); if (client != null) { client.Dispose(); } } } else { Frame.Navigate(typeof(MainPage), e); } }