Skip to content
A wrapper around microsoft identity connector and microsoft graph api to access one drive content
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sample
srcs
tests
.gitignore
LICENSE
README.md

README.md

Xamarin.OneDrive.Connector

A wrapper around microsoft identity connector and microsoft graph api to access one drive content

Sample of how to use the library

Simplest get-started sample

   using Xamarin.OneDrive;

   var connector = new Connector("YOUR_MICROSOFT_APPLICATION_ID", "User.Read");
   if (await connector.ConnectAsync())
   {
      var httpMessage = await connector.GetAsync("me");
      /* json message with the requested data */
   }
   connector.Dispose();

Using the profile plugin to request user profile data

   using Xamarin.OneDrive;
   using Xamarin.OneDrive.Profile;

   var connector = new Connector("YOUR_MICROSOFT_APPLICATION_ID", "User.Read");
   if (await connector.ConnectAsync())
   {
      var profile = await connector.GetProfileAsync();
      Console.WriteLine($"Connected to {profile.Name} account through address {profile.Mail}");
   }
   connector.Dispose();

Using the files plugin to search download and manipulate files stored in OneDrive

   using Xamarin.OneDrive;
   using Xamarin.OneDrive.Files;

   var connector = new Connector("YOUR_MICROSOFT_APPLICATION_ID", "Files.Read");
   if (await connector.ConnectAsync())
   {
      var fileList = await connector.SearchFilesAsync("*.zip");
      Console.WriteLine($"Retrieved {fileList.Count} files on the search request");
      var file = fileList[0];
      Console.WriteLine($"The file {file.FileName} has {file.Bytes} bytes and is located on {file.FilePath}.");
   }
   connector.Dispose();

Android project required MainActivity overrides

protected override void OnCreate(Bundle savedInstanceState)
{
   ...
   Xamarin.Forms.Forms.Init(this, savedInstanceState);
   Xamarin.OneDrive.Connector.Init(this); /* optionally we could pass a specific redirectUrl */
   ...
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
   base.OnActivityResult(requestCode, resultCode, data);
   Xamarin.OneDrive.Connector.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data);
}

Install instructions

  • You can add the library to your project using the nuget package:

    dotnet add package Xamarin.OneDrive.Connector
  • And the optionals plugins:

    dotnet add package Xamarin.OneDrive.Connector.Profile  
    dotnet add package Xamarin.OneDrive.Connector.Files  
  • You will nedd a microsoft application id that you can get following this guide.

Build using

Changelog

v0.1.*

Trying to learn and apply unit tests (quantum physics for me).
Conditional framework's builds according to platform specifics, need because android requires some extras steps on acquiring token.
Extending the HttpClient library to accommodate token acquisition.
Implementing the plugin concept using profile as the first try.
Preparing projects to be build, packed and deploy by the server.
Provide a sample application. Implementing the UploadAsync method to send file content to drive. SearchFiles overloads to allow searching on specific folder.
Methods for listing folder's childs.

v0.2.*

Upgrading Microsoft Identity Client.

Authors

License

MIT License - see the LICENSE file for details.

You can’t perform that action at this time.