public void Setup() { this.appConfig = new AppConfig(); this.authenticationProvider = new MockAuthenticationProvider(); this.authenticationProvider.Setup(provider => provider.AppendAuthHeaderAsync(It.IsAny <HttpRequestMessage>())).Returns(Task.FromResult(0)); this.credentialCache = new MockCredentialCache(); this.serializer = new MockSerializer(); this.httpResponseMessage = new HttpResponseMessage(); this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object); this.serviceInfo = new ServiceInfo { AuthenticationProvider = this.authenticationProvider.Object, }; this.serviceInfoProvider = new MockServiceInfoProvider(this.serviceInfo); this.webUi = new MockWebUi(); this.oneDriveClient = new OneDriveClient( this.appConfig, this.credentialCache.Object, this.httpProvider.Object, this.serviceInfoProvider.Object) { BaseUrl = Constants.Authentication.OneDriveConsumerBaseUrl, ServiceInfo = this.serviceInfo, }; }
public async Task <bool> AuthenticateAsync() { try { oneDriveClient = OneDriveClientExtensions.GetUniversalClient(Scopes); await oneDriveClient.AuthenticateAsync(); } catch { System.Diagnostics.Debug.WriteLine("Fail auth. Make sure app is registered in store."); } try { // little hack to make shure the service works await oneDriveClient.Drive.Request().GetAsync(); IsAuthenticated = true; } catch (Exception) { IsAuthenticated = false; } return(IsAuthenticated); }
public async Task <IOneDriveClient> LoginAsync() { try { if (oneDriveClient == null) { oneDriveClient = OneDriveClientExtensions.GetUniversalClient(ServiceConstants.Scopes); await oneDriveClient.AuthenticateAsync(); } if (!oneDriveClient.IsAuthenticated) { await oneDriveClient.AuthenticateAsync(); } return(oneDriveClient); } catch (OneDriveException exception) { // Swallow authentication cancelled exceptions if (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString())) { if (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString())) { await dialogService.ShowMessage( "Authentication failed", "Authentication failed"); } else { throw; } } } return(oneDriveClient); }
public async Task <bool> AuthenticateNew(CancellationToken cs) { //msaAuthenticationProvider = new MsaAuthenticationProvider(MicrosoftSecret.ClientId, MicrosoftSecret.ClientSecret, "http://localhost:8000/callback.html", Scopes, null, new CredentialsVault(this, null)); //await msaAuthenticationProvider.AuthenticateUserAsync().ConfigureAwait(false); //oneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthenticationProvider); //return msaAuthenticationProvider.IsAuthenticated; Task authTask; var adalAuthProvider = new AdalAuthenticationProvider( "053488e0-5bf2-467b-8866-45d00c5b187b", "https://boschsg.onmicrosoft.com/OneDriveApi2"); //oneDriveClient = new OneDriveClient("https://boschsg-my.sharepoint.com" + "/_api/v2.0", adalAuthProvider); oneDriveClient = new OneDriveClient("https://boschsg-my.sharepoint.com" + "/_api/v2.0", adalAuthProvider); authTask = adalAuthProvider.AuthenticateUserAsync("https://boschsg-my.sharepoint.com"); try { await authTask; } catch (ServiceException exception) { Console.WriteLine(exception.Error); } return(true); }
private async void OnOneDriveWebViewLogin(object sender, RoutedEventArgs e) { _client = OneDriveClientExtensions.GetClientUsingWebAuthenticationBroker(ClientId, Scopes); await _client.AuthenticateAsync(); refreshToken = _client.AuthenticationProvider.CurrentAccountSession.RefreshToken; ApplicationData.Current.LocalSettings.Values["RefreshToken"] = refreshToken; }
public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); if (ApplicationData.Current.LocalSettings.Values.ContainsKey("RefreshToken")) { string refreshToken = ApplicationData.Current.LocalSettings.Values["RefreshToken"].ToString(); string returnUrl = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString(); IOneDriveClient client = await OneDriveClient.GetSilentlyAuthenticatedMicrosoftAccountClient(ClientId, returnUrl, Scopes, refreshToken); bool isFolderExisting = true; try { await client.Drive.Root.ItemWithPath("OneDrive Sample").Request().GetAsync(); } catch (OneDriveException exc) { isFolderExisting = false; } if (isFolderExisting) { StorageFile file = await Package.Current.InstalledLocation.GetFileAsync("BackgroundWallpaper.jpg"); using (Stream stream = await file.OpenStreamForReadAsync()) { await client.Drive.Root.ItemWithPath("OneDrive Sample/BackgroundWallpaper.png").Content.Request().PutAsync <Item>(stream); } } } deferral.Complete(); }
public async Task Setup() { // onedrive var scopes = new string[] { "wl.basic", "wl.signin", "onedrive.readwrite" }; client = OneDriveClientExtensions.GetUniversalClient(scopes); session = await client.AuthenticateAsync(); }
/// <summary> /// Constructs a new ThumbnailContentRequest. /// <param name="requestUrl">The request URL.</param> /// <param name="oneDriveClient">The <see cref="IOneDriveClient"/> for handling requests.</param> /// <param name="options">Query option name value pairs for the request.</param> /// </summary> public ThumbnailContentRequest( string requestUrl, IOneDriveClient oneDriveClient, IList <Option> options) : base(requestUrl, oneDriveClient, options) { }
/// <summary> /// Constructs a new <see cref="BaseRequest"/>. /// </summary> /// <param name="requestUrl">The URL for the request.</param> /// <param name="oneDriveClient">The <see cref="IOneDriveClient"/> for handling requests.</param> /// <param name="options">The header and query options for the request.</param> public BaseRequest( string requestUrl, IOneDriveClient oneDriveClient = null, IEnumerable <Option> options = null) { this.Method = "GET"; this.OneDriveClient = oneDriveClient; this.Headers = new List <HeaderOption>(); this.QueryOptions = new List <QueryOption>(); this.RequestUrl = this.InitializeUrl(requestUrl); if (options != null) { var headerOptions = options.OfType <HeaderOption>(); if (headerOptions != null) { ((List <HeaderOption>) this.Headers).AddRange(headerOptions); } var queryOptions = options.OfType <QueryOption>(); if (queryOptions != null) { ((List <QueryOption>) this.QueryOptions).AddRange(queryOptions); } } this.requestStatsHeaderValue = string.Format( Constants.Headers.RequestStatsFormatString, this.GetType().GetTypeInfo().Assembly.GetName().Version); }
private async void Continue_Tapped(object sender, TappedRoutedEventArgs e) { try { MainPage.ShowLoader(ResourceLoader.GetForCurrentView().GetString("SynchronizingAccountsWithCloud")); IOneDriveClient oneDriveClient = OneDriveClientExtensions.GetUniversalClient(new[] { "onedrive.appfolder" }); AccountSession session = await oneDriveClient.AuthenticateAsync(); IEncrypter encrypter = new AESEncrypter(); if (session.AccountType == AccountType.MicrosoftAccount) { synchronizer.SetEncrypter(encrypter, userKey); await AccountStorage.Instance.Synchronize(); MainPage.HideLoader(); Frame.Navigate(typeof(SetupSynchronizationFinishedPage), mainPage); } } catch (OneDriveException ex) { MessageDialog dialog = GetOneDriveErrorMessageDialog(ex); await dialog.ShowAsync(); } }
private async void btnLogin_Click(object sender, RoutedEventArgs e) { try { oneDriveClient = OneDriveClientExtensions.GetUniversalClient(scopes); var accountSession = await oneDriveClient.AuthenticateAsync(); if (accountSession != null) { var rootItem = await oneDriveClient .Drive .Root .Request() .GetAsync(); var items = await oneDriveClient .Drive .Items[rootItem.Id] .Children .Request() .GetAsync(); gridView.ItemsSource = items.CurrentPage; } } catch (OneDriveException oe) { txtMsg.Text = "登陆失败"; } }
/// <summary> /// Constructs a new SharesCollectionRequest. /// </summary> /// <param name="requestUrl">The request URL.</param> /// <param name="oneDriveClient">The <see cref="IOneDriveClient"/> for handling requests.</param> /// <param name="options">Query option name value pairs for the request.</param> public SharesCollectionRequest( string requestUrl, IOneDriveClient oneDriveClient, IList <Option> options) : base(requestUrl, oneDriveClient, options) { }
/// <summary> /// Constructs a new ThumbnailRequest. /// </summary> /// <param name="requestUrl">The request URL.</param> /// <param name="oneDriveClient">The <see cref="IOneDriveClient"/> for handling requests.</param> /// <param name="options">Query option name value pairs for the request.</param> public ThumbnailRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options) : base(requestUrl, oneDriveClient, options) { }
async Task <bool> get_authorize() { var msaAuthProvider = new MsaAuthenticationProvider( MsaClientId, MsaReturnUrl, Scopes, new CredentialVault(MsaClientId) ); try { await msaAuthProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(); oneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthProvider); return(true); } catch (ServiceException ex) { MessageBox.Show( ex.Error.Message, "Authentication failed", MessageBoxButtons.OK); return(false); } }
/// <summary> /// Constructs a new DriveAllPhotosRequest. /// </summary> public DriveAllPhotosRequest( string requestUrl, IOneDriveClient oneDriveClient, IList <Option> options) : base(requestUrl, oneDriveClient, options) { }
private async void btnLogin_Click(object sender, RoutedEventArgs e) { try { oneDriveClient = OneDriveClientExtensions.GetUniversalClient(scopes); var accountSession = await oneDriveClient.AuthenticateAsync(); if (accountSession!=null) { var rootItem = await oneDriveClient .Drive .Root .Request() .GetAsync(); var items=await oneDriveClient .Drive .Items[rootItem.Id] .Children .Request() .GetAsync(); gridView.ItemsSource = items.CurrentPage; } } catch (OneDriveException oe) { txtMsg.Text="登陆失败"; } }
/// <summary> /// Constructs a new ItemRequest. /// </summary> /// <param name="requestUrl">The request URL.</param> /// <param name="oneDriveClient">The <see cref="IOneDriveClient"/> for handling requests.</param> /// <param name="options">Query option name value pairs for the request.</param> public ItemRequest( string requestUrl, IOneDriveClient oneDriveClient, IList <Option> options) : base(requestUrl, oneDriveClient, options) { }
/// <summary> /// Constructs a new SpecialCollectionRequest. /// </summary> /// <param name="requestUrl">The request URL.</param> /// <param name="oneDriveClient">The <see cref="IOneDriveClient"/> for handling requests.</param> /// <param name="options">Query option name value pairs for the request.</param> public SpecialCollectionRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options) : base(requestUrl, oneDriveClient, options) { }
/// <summary> /// Constructs a new DriveSharedWithMeRequest. /// </summary> public DriveSharedWithMeRequest( string requestUrl, IOneDriveClient oneDriveClient, IList <Option> options) : base(requestUrl, oneDriveClient, options) { }
/// <summary> /// Initializes a new instance of the <see cref="OneDriveRequestSource{T}"/> class. /// </summary> /// <param name="provider">OneDrive Data Client Provider</param> /// <param name="requestBuilder">Http request to execute</param> /// <param name="orderBy">Sort the order of items in the response collection</param> /// <param name="filter">Filters the response based on a set of criteria.</param> public OneDriveRequestSource(IOneDriveClient provider, IItemRequestBuilder requestBuilder, OrderBy orderBy, string filter) { _provider = provider; _requestBuilder = requestBuilder; _orderBy = orderBy; _filter = filter; }
/// <summary> /// Constructs a new PermissionRequest. /// </summary> /// <param name="requestUrl">The request URL.</param> /// <param name="oneDriveClient">The <see cref="IOneDriveClient"/> for handling requests.</param> /// <param name="options">Query option name value pairs for the request.</param> public PermissionRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options) : base(requestUrl, oneDriveClient, options) { }
/// <inheritdoc/> public async Task <bool> LoginAsync() { _isConnected = false; if (!_isInitialized) { throw new InvalidOperationException("Microsoft OneDrive not initialized."); } OneDriveAuthenticationHelper.ResourceUri = "https://api.onedrive.com/v1.0"; if (_accountProviderType == AccountProviderType.Msa) { _accountProvider = OneDriveAuthenticationHelper.CreateMSAAuthenticationProvider(_appClientId, _scopes); await OneDriveAuthenticationHelper.AuthenticateMsaUserAsync(); } else if (_accountProviderType == AccountProviderType.OnlineId) { _accountProvider = new OnlineIdAuthenticationProvider(_scopes); await((OnlineIdAuthenticationProvider)_accountProvider).RestoreMostRecentFromCacheOrAuthenticateUserAsync(); } _oneDriveProvider = new OneDriveClient(OneDriveAuthenticationHelper.ResourceUri, _accountProvider); _isConnected = true; return(_isConnected); }
public void Setup() { this.appConfig = new AppConfig(); this.authenticationProvider = new MockAuthenticationProvider(); this.authenticationProvider.Setup(provider => provider.AuthenticateAsync()).Returns(Task.FromResult(new AccountSession())); this.authenticationProvider.Setup(provider => provider.AppendAuthHeaderAsync(It.IsAny<HttpRequestMessage>())).Returns(Task.FromResult(0)); this.credentialCache = new MockCredentialCache(); this.serializer = new MockSerializer(); this.httpResponseMessage = new HttpResponseMessage(); this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object); this.serviceInfo = new ServiceInfo { AuthenticationProvider = this.authenticationProvider.Object, }; this.serviceInfoProvider = new MockServiceInfoProvider(this.serviceInfo); this.webUi = new MockWebAuthenticationUi(); this.oneDriveClient = new OneDriveClient( this.appConfig, this.credentialCache.Object, this.httpProvider.Object, this.serviceInfoProvider.Object) { BaseUrl = string.Format(Constants.Authentication.OneDriveConsumerBaseUrlFormatString, "v1.0"), ServiceInfo = this.serviceInfo, }; }
/// <summary> /// Initializes a new instance of the <see cref="OneDriveStorageItem"/> class. /// </summary> /// <param name="oneDriveProvider">Instance of OneDriveClient class</param> /// <param name="requestBuilder">Http request builder.</param> /// <param name="oneDriveItem">OneDrive's item</param> public OneDriveStorageItem(IOneDriveClient oneDriveProvider, IItemRequestBuilder requestBuilder, Item oneDriveItem) { _requestBuilder = requestBuilder; _oneDriveProvider = oneDriveProvider; _oneDriveItem = oneDriveItem; _name = oneDriveItem.Name; _dateCreated = oneDriveItem.CreatedDateTime; _dateModified = oneDriveItem.LastModifiedDateTime; _displayName = _name; _folderId = oneDriveItem.Id; if (IsFile()) { _displayType = "File"; } else if (IsFolder()) { _displayType = "Folder"; } else { _displayType = "OneNote"; } // ParentReference null means is root if (oneDriveItem.ParentReference != null) { _path = oneDriveItem.ParentReference.Path.Replace("/drive/root:", string.Empty); } }
public ItemSearchRequestBuilder( string requestUrl, IOneDriveClient oneDriveClient, string q = null) : base(requestUrl, oneDriveClient) { this.Q = q; }
private void Page_Loaded(object sender, RoutedEventArgs e) { oneDriveClient = OneDriveClientExtensions.GetUniversalClient(new[] { "onedrive.appfolder" }); vault = new PasswordVault(); ShowInformation(); }
public ItemCreateLinkRequestBuilder( string requestUrl, IOneDriveClient oneDriveClient, string type = null) : base(requestUrl, oneDriveClient) { this.Type = type; }
/// <summary> /// Constructs a new DriveSharedWithMeRequest. /// </summary> public DriveSharedWithMeRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options) : base(requestUrl, oneDriveClient, options) { }
public ItemCreateSessionRequestBuilder( string requestUrl, IOneDriveClient oneDriveClient, ChunkedUploadSessionDescriptor item = null) : base(requestUrl, oneDriveClient) { this.Item = item; }
/// <summary> /// Constructs a new ItemAllPhotosRequest. /// </summary> public ItemAllPhotosRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options) : base(requestUrl, oneDriveClient, options) { }
public ItemDeltaRequestBuilder( string requestUrl, IOneDriveClient oneDriveClient, string token = null) : base(requestUrl, oneDriveClient) { this.Token = token; }
public async Task <bool> AuthenticateSaved(CancellationToken cs, string save) { msaAuthenticationProvider = new MsaAuthenticationProvider(MicrosoftSecret.ClientId, MicrosoftSecret.ClientSecret, "http://localhost:45674/authredirect", Scopes, null, new CredentialsVault(this, save)); await msaAuthenticationProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync().ConfigureAwait(false); oneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthenticationProvider); return(msaAuthenticationProvider.IsAuthenticated); }
public OneDriveCloudService( IOneDriveClient oneDriveClient, ISimpleDataStorage simpleDataStorage, IClock clock) { _oneDriveClient = oneDriveClient; _simpleDataStorage = simpleDataStorage; _clock = clock; }
/// <summary> /// Signs in the user /// </summary> /// <returns>Returns success or failure of login attempt.</returns> public override async Task <bool> LoginAsync() { IsConnected = false; if (!IsInitialized) { throw new InvalidOperationException("Microsoft OneDrive not initialized."); } string resourceEndpointUri = null; if (_accountProviderType == AccountProviderType.Adal) { DiscoveryService discoveryService = null; DiscoverySettings discoverySettings = DiscoverySettings.Load(); if (discoverySettings == null) { // For OneDrive for business only var authDiscoveryResult = await OneDriveAuthenticationHelper.AuthenticateAdalUserForDiscoveryAsync(AppClientId); discoveryService = await OneDriveAuthenticationHelper.GetUserServiceResource(authDiscoveryResult); discoverySettings = new DiscoverySettings { ServiceEndpointUri = discoveryService.ServiceEndpointUri, ServiceResourceId = discoveryService.ServiceResourceId }; discoverySettings.Save(); } OneDriveAuthenticationHelper.ResourceUri = discoverySettings.ServiceResourceId; _accountProvider = OneDriveAuthenticationHelper.CreateAdalAuthenticationProvider(AppClientId); await OneDriveAuthenticationHelper.AuthenticateAdalUserAsync(true); resourceEndpointUri = discoverySettings.ServiceEndpointUri; } else if (_accountProviderType == AccountProviderType.Msa) { OneDriveAuthenticationHelper.ResourceUri = "https://api.onedrive.com/v1.0"; _accountProvider = OneDriveAuthenticationHelper.CreateMSAAuthenticationProvider(AppClientId, Scopes); await((MsaAuthenticationProvider)OneDriveAuthenticationHelper.AuthenticationProvider).RestoreMostRecentFromCacheOrAuthenticateUserAsync(); resourceEndpointUri = OneDriveAuthenticationHelper.ResourceUri; } else if (_accountProviderType == AccountProviderType.OnlineId) { OneDriveAuthenticationHelper.ResourceUri = "https://api.onedrive.com/v1.0"; _accountProvider = new OnlineIdAuthenticationProvider(Scopes); await((MsaAuthenticationProvider)_accountProvider).RestoreMostRecentFromCacheOrAuthenticateUserAsync(); resourceEndpointUri = OneDriveAuthenticationHelper.ResourceUri; } _oneDriveProvider = new OneDriveClient(resourceEndpointUri, _accountProvider); IsConnected = true; return(IsConnected); }
public ItemCopyRequestBuilder( string requestUrl, IOneDriveClient oneDriveClient, string name = null, ItemReference parentReference = null) : base(requestUrl, oneDriveClient) { this.Name = name; this.ParentReference = parentReference; }
/// <summary> /// Initializes the NextPageRequest property. /// </summary> public void InitializeNextPageRequest(IOneDriveClient oneDriveClient, string nextPageLinkString) { if (!string.IsNullOrEmpty(nextPageLinkString)) { this.NextPageRequest = new ItemSearchRequest( nextPageLinkString, oneDriveClient, null); } }
public async Task SignOut(string save) { if (oneDriveClient != null) { await msaAuthenticationProvider.SignOutAsync(); msaAuthenticationProvider = null; oneDriveClient = null; } }
/// <summary> /// Initializes the NextPageRequest property. /// </summary> public void InitializeNextPageRequest(IOneDriveClient oneDriveClient, string nextPageLinkString) { if (!string.IsNullOrEmpty(nextPageLinkString)) { this.NextPageRequest = new ThumbnailsCollectionRequest( nextPageLinkString, oneDriveClient, null); } }
public void Setup() { this.authenticationProvider = new MockAuthenticationProvider(); this.serializer = new MockSerializer(); this.httpResponseMessage = new HttpResponseMessage(); this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object); this.oneDriveClient = new OneDriveClient( "https://api.onedrive.com/v1.0", this.authenticationProvider.Object, this.httpProvider.Object); }
async private void Initialize() { try { if (oneDriveClient == null) { oneDriveClient = OneDriveClientExtensions.GetClientUsingOnlineIdAuthenticator(scopes); await oneDriveClient.AuthenticateAsync(); } } catch (Exception ex) { } }
/// <summary> /// Constructs a new ItemCreateSessionRequest. /// </summary> public ItemCreateSessionRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options, ChunkedUploadSessionDescriptor item = null) : base(requestUrl, oneDriveClient, options) { this.Method = "POST"; this.ContentType = "application/json"; this.RequestBody = new ItemCreateSessionRequestBody(); this.RequestBody.Item = item; }
/// <summary> /// Constructs a new ItemCreateLinkRequest. /// </summary> public ItemCreateLinkRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options, string type = null) : base(requestUrl, oneDriveClient, options) { this.Method = "POST"; this.ContentType = "application/json"; this.RequestBody = new ItemCreateLinkRequestBody(); this.RequestBody.Type = type; }
public async Task<IOneDriveClient> LoginAsync() { if (oneDriveClient == null) { oneDriveClient = OneDriveClient.GetMicrosoftAccountClient( ServiceConstants.MSA_CLIENT_ID, ServiceConstants.RETURN_URL, ServiceConstants.Scopes, ServiceConstants.MSA_CLIENT_SECRET, null, null, new CustomServiceInfoProvider()); try { await oneDriveClient.AuthenticateAsync(); } catch (Exception ex) { Debug.Write(ex); } } try { if (!oneDriveClient.IsAuthenticated) { await oneDriveClient.AuthenticateAsync(); } return oneDriveClient; } catch (OneDriveException exception) { // Swallow authentication cancelled exceptions if (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString())) { if (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString())) { await dialogService.ShowMessage( "Authentication failed", "Authentication failed"); } else { throw; } } } return oneDriveClient; }
private async void AADAuthenticate() { if (oneDriveClient != null) return; oneDriveClient = BusinessClientExtensions.GetClient( new AppConfig() { ActiveDirectoryAppId = _clientIDAAD, ActiveDirectoryClientSecret = _clientSecretAAD, ActiveDirectoryReturnUrl = _returnUrlAAD, ActiveDirectoryServiceEndpointUrl = _oneDriveApiEndpointAAD, ActiveDirectoryServiceResource = _serviceResourceIdAAD, ActiveDirectoryAuthenticationServiceUrl = _serviceUrlAAD }); await oneDriveClient?.AuthenticateAsync(); }
/// <summary> /// Constructs a new ItemDeltaRequest. /// </summary> public ItemDeltaRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options, string token = null) : base(requestUrl, oneDriveClient, options) { this.Method = "GET"; if (token != null) { this.QueryOptions.Add(new QueryOption("token", token)); } }
/// <summary> /// Constructs a new ItemSearchRequest. /// </summary> public ItemSearchRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options, string q = null) : base(requestUrl, oneDriveClient, options) { this.Method = "GET"; if (q != null) { this.QueryOptions.Add(new QueryOption("q", q)); } }
public async Task<AccountSession> Initialize() { // onedrive try { var scopes = new string[] { "wl.basic", "wl.signin", "onedrive.readwrite" }; client = OneDriveClientExtensions.GetUniversalClient(scopes); return await client.AuthenticateAsync(); } catch (Exception) { throw; } }
/// <summary> /// Constructs a new ItemCopyRequest. /// </summary> public ItemCopyRequest( string requestUrl, IOneDriveClient oneDriveClient, IList<Option> options, string name = null, ItemReference parentReference = null) : base(requestUrl, oneDriveClient, options) { this.Method = "POST"; this.Headers.Add(new HeaderOption("Prefer", "respond-async")); this.ContentType = "application/json"; this.RequestBody = new ItemCopyRequestBody(); this.RequestBody.Name = name; this.RequestBody.ParentReference = parentReference; }
private async void saveToOneDriveToolStripMenuItem_Click(object sender, EventArgs e) { if (oneDriveClient == null) { oneDriveClient = OneDriveClient.GetMicrosoftAccountClient( OneDriveClientID, "https://login.live.com/oauth20_desktop.srf", new string[] { "onedrive.readwrite", "wl.offline_access", "wl.signin" }, webAuthenticationUi: new FormsWebAuthenticationUi()); } try { if (!oneDriveClient.IsAuthenticated) { await oneDriveClient.AuthenticateAsync(); } } catch (OneDriveException) { MessageBox.Show("Authentication failed", "Error", MessageBoxButtons.OK); return; } try { var tmpFile = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllText(tmpFile, txContent.Text); var stream = new System.IO.FileStream(tmpFile, System.IO.FileMode.Open); var filename = DateTime.Now.ToString("yyyy_MM_dd_mm_ss") + "_MonoChat.txt"; var uploadPath = @"/drive/items/root:/" + filename; var uploadedItem = await this.oneDriveClient.ItemWithPath(uploadPath).Content.Request().PutAsync<Item>(stream); MessageBox.Show("Chat histroy saved!", "Success", MessageBoxButtons.OK); stream.Close(); } catch (Exception) { MessageBox.Show("Chat histroy could not be saved!", "Error", MessageBoxButtons.OK); } }
public async Task<IOneDriveClient> LoginAsync() { if (oneDriveClient == null) { oneDriveClient = OneDriveClientExtensions.GetClientUsingWebAuthenticationBroker(MSA_CLIENT_ID, scopes); await oneDriveClient.AuthenticateAsync(); } try { if (!oneDriveClient.IsAuthenticated) { await oneDriveClient.AuthenticateAsync(); } return oneDriveClient; } catch (OneDriveException exception) { // Swallow authentication cancelled exceptions if (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString())) { if (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString())) { await dialogService.ShowMessage( "Authentication failed", "Authentication failed"); } else { throw; } } } return oneDriveClient; }
/// <summary> /// Constructs a new SharesCollectionRequestBuilder. /// </summary> /// <param name="requestUrl">The URL for the built request.</param> /// <param name="oneDriveClient">The <see cref="IOneDriveClient"/> for handling requests.</param> public SharesCollectionRequestBuilder( string requestUrl, IOneDriveClient oneDriveClient) : base(requestUrl, oneDriveClient) { }
public OneDriveTile(IOneDriveClient oneDriveClient) { this.oneDriveClient = oneDriveClient; InitializeComponent(); }
private async Task AuthenticateOneDrive() { string[] scopes = { "wl.signin", "wl.offline_access", "onedrive.readwrite" }; oneDriveClient = OneDriveClientExtensions.GetClientUsingOnlineIdAuthenticator(scopes); await oneDriveClient.AuthenticateAsync(); }
public DriveRecentRequestBuilder( string requestUrl, IOneDriveClient oneDriveClient) : base(requestUrl, oneDriveClient) { }