2016-07-26 81 views
1

我試圖連接使用MSAL令牌OneDrive但它返回錯誤=「INVALID_TOKEN」,ERROR_DESCRIPTION =「驗證錯誤」如何使用MSAL連接到Onedrive?

這是我的代碼:

public static string[] Scopes = { "User.Read", "Files.Read", "Sites.Read.All" }; 
    AuthenticationResult ar = await App.ClientApplication.AcquireTokenSilentAsync(Scopes); 
    WelcomeText.Text = $"Welcome {ar.User.Name}"; //Login OK here 

     //get data from API 
     HttpClient client = new HttpClient(); 
     HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.onedrive.com/v1.0/drives"); 
     message.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", ar.Token); 
     HttpResponseMessage response = await client.SendAsync(message); 
     string responseString = await response.Content.ReadAsStringAsync(); 

任何人都知道我是什麼做錯了?

回答

1

直接API端點(api.onedrive.com)不支持從MSAL生成的訪問令牌,僅支持從MSA生成的令牌。如果您使用的是MSAL,則應使用Microsoft Graph API(graph.microsoft.com)訪問個人和企業用戶的OneDrive文件。

+0

It Works!謝謝! – transis