OneDrive for Business :“invalid_request”,“error_description”:\"AADSTS90014: The request body must contain the following parameter: 'grant_type

扶醉桌前 提交于 2019-12-05 03:13:20

You're adding the parameters to the request querystring. You have to post the data in the request body.

var content = new StringContent(
                "grant_type=authorization_code" +
                "&client_id=" + ClienId +
                "&redirect_uri=" + Redirecturi +
                "&client_secret=" + ClientSecert +
                "&code=" + _accessCode +
                "&resource=" + ResourcesId,
                Encoding.UTF8, 
                "application/x-www-form-urlencoded");

var response = httpClient.PostAsync(BaseUri, content);

var result = response.Result.Content.ReadAsStringAsync();

use FormUrlEncodedContent instead of StringContent (form data post)

var formContent = new FormUrlEncodedContent(new Dictionary<string, string>
{
    { "client_id", clientId },
    { "client_secret", clientSecret },
    { "code", authCode },
    { "redirect_uri", redirectUri },
    { "grant_type", "authorization_code" }
});

var response = await httpClient.PostAsync("https://login.microsoftonline.com/common/oauth2/token", formContent);

Sharing for future readers because this error is not specific to OneDrive only but can arise in other Microsoft tools

I was getting this error when working with Microsoft Bot Framework's Skype bot. In my case the bot file the appId and appSecret was wrongly set to clientId and clientSecret

Changing the same to appId and appSecret fixed the issue.

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