Onedrive API vs LiveSDK

限于喜欢 提交于 2019-12-03 23:21:08

[Solution extracted from question to get out of "unanswered" stack]

In summary, my current method is the following:

  1. Authenticate using LiveSDK API
  2. Use the session cookie and the OneDrive API from there

The simplified code is the following:

The method below allows to log in silently, only the first time requires a manual validation from the user allowing the program to use its Live account.

It does not require any password from the user

var authClient = new LiveAuthClient();
var authResult = await authClient.LoginAsync(new string[] {  
        "wl.signin", "onedrive.readwrite", "onedrive.appfolder"});

if (authResult.Session == null)
    throw new InvalidOperationException("You need to sign in and give consent to the app.");

var Connection = new ODConnection("https://api.onedrive.com/v1.0", 
    new MicrosoftAccountAuthenticationInfo() { TokenType = "Bearer", 
    AccessToken = odArgs.Session.AccessToken });

It is not as clean as I would like (using 2 different SDK), but it works :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!