private async Task InitOneDrive() { string[] scopes = { "onedrive.readonly", "wl.signin" }; try { // get provider authenticationProvider = new OnlineIdAuthenticationProvider(scopes); await authenticationProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(); // init client oneDriveClient = new OneDriveClient(BaseUrl, authenticationProvider); } catch (Exception e) { Analytics.TrackEvent("Exception when initializing OneDrive", new Dictionary <string, string> { { "Error", e.Message }, { "InnerError", e.InnerException != null ? e.InnerException.Message : "" }, { "Where", "MainPage.xaml:InitOneDrive" } }); authenticationProvider = null; oneDriveClient = null; throw; } }
public async Task Authenticate() { var msaAuthenticationProvider = new OnlineIdAuthenticationProvider(new string[] { "onedrive.readwrite" }); await msaAuthenticationProvider.AuthenticateUserAsync(); client = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthenticationProvider); }
/// <inheritdoc /> public async Task <IGraphServiceClient> LoginAsync() { try { var msaAuthenticationProvider = new OnlineIdAuthenticationProvider(ServiceConstants.Scopes, isBackground ? OnlineIdAuthenticationProvider.PromptType.DoNotPrompt : OnlineIdAuthenticationProvider.PromptType.PromptIfNeeded); await msaAuthenticationProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync() .ConfigureAwait(true); return(new GraphServiceClient(ServiceConstants.BASE_URL, msaAuthenticationProvider)); } catch (ServiceException serviceException) { Debug.WriteLine(serviceException); throw new BackupException("Authentication Failed with Graph.ServiceException", serviceException); } catch (Exception ex) { Debug.WriteLine(ex); throw new BackupException("Authentication Failed", ex); } }
private async Task loggin() { msaProvider = new OnlineIdAuthenticationProvider(scopes); await msaProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(); this.client = new OneDriveClient(msaProvider); }
/* * Sign out */ public static async void OneDriveSignOut() { try { var msaAuthenticationProvider = new OnlineIdAuthenticationProvider(scopes); await msaAuthenticationProvider.SignOutAsync(); } catch { } }
private async void InitializeClient(ClientType clientType, RoutedEventArgs e) { var app = (App)Application.Current; if (app.OneDriveClient == null) { Task authTask; if (clientType == ClientType.Business) { var adalAuthProvider = new AdalAuthenticationProvider( this.oneDriveForBusinessClientId, this.oneDriveForBusinessReturnUrl); authTask = adalAuthProvider.AuthenticateUserAsync(this.oneDriveForBusinessBaseUrl); app.OneDriveClient = new OneDriveClient(this.oneDriveForBusinessBaseUrl + "/_api/v2.0", adalAuthProvider); app.AuthProvider = adalAuthProvider; } else if (clientType == ClientType.ConsumerUwp) { var onlineIdAuthProvider = new OnlineIdAuthenticationProvider( this.scopes); authTask = onlineIdAuthProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(); app.OneDriveClient = new OneDriveClient(this.oneDriveConsumerBaseUrl, onlineIdAuthProvider); app.AuthProvider = onlineIdAuthProvider; } else { var msaAuthProvider = new MsaAuthenticationProvider( this.oneDriveConsumerClientId, this.oneDriveConsumerReturnUrl, this.scopes, new CredentialVault(this.oneDriveConsumerClientId)); authTask = msaAuthProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(); app.OneDriveClient = new OneDriveClient(this.oneDriveConsumerBaseUrl, msaAuthProvider); app.AuthProvider = msaAuthProvider; } try { await authTask; app.NavigationStack.Add(new ItemModel(new Item())); this.Frame.Navigate(typeof(MainPage), e); } catch (ServiceException exception) { // Swallow the auth exception but write message for debugging. Debug.WriteLine(exception.Error.Message); } } else { this.Frame.Navigate(typeof(MainPage), e); } }
/* * Verify if the user has been logged on OneDrive */ public static async Task <bool> VerifyOneDriveLogin() { var msaAuthenticationProvider = new OnlineIdAuthenticationProvider(scopes); await msaAuthenticationProvider.RestoreMostRecentFromCacheAsync(); if (msaAuthenticationProvider.CurrentAccountSession != null) { return(true); } else { return(false); } }
/// <summary> /// Perform an async Login Request /// </summary> public async Task <IOneDriveClient> LoginAsync() { try { var msaAuthenticationProvider = new OnlineIdAuthenticationProvider(ServiceConstants.Scopes); await msaAuthenticationProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(); return(new OneDriveClient(ServiceConstants.BASE_URL, msaAuthenticationProvider)); } catch (ServiceException serviceException) { Debug.WriteLine(serviceException); throw new BackupException("Authentication Failed with Graph.ServiceException", serviceException); } catch (Exception ex) { Debug.WriteLine(ex); throw new BackupException("Authentication Failed", ex); } }
/* * Authentification to OneDrive */ public static async Task <bool> OneDriveAuthentification() { try { var msaAuthenticationProvider = new OnlineIdAuthenticationProvider(scopes); if (!msaAuthenticationProvider.IsAuthenticated) { await msaAuthenticationProvider.AuthenticateUserAsync(); await msaAuthenticationProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(); TabsDataCache.OneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthenticationProvider); TabsDataCache.AuthProvider = msaAuthenticationProvider; return(true); } else { return(true); } } catch { return(false); } }
public async Task Initialize() { try { if (initializationInProgress) { return; } initializationInProgress = true; var msaAuthenticationProvider = new OnlineIdAuthenticationProvider(new[] { "onedrive.readwrite", "wl.signin" }); await msaAuthenticationProvider.AuthenticateUserAsync(); oneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthenticationProvider); notInitialized = false; await MoveFromOldFolder(); } catch { notInitialized = true; } }
public void InitInstance() { msaAuthenticationProvider = new OnlineIdAuthenticationProvider(new string[] { "onedrive.appfolder", "offline_access" }); oneDriveClient = new OneDriveClient(msaAuthenticationProvider); }