OneDrive for Business:"invalid

编程入门 行业动态 更新时间:2024-10-08 13:35:10
本文介绍了OneDrive for Business:"invalid_request","error_description":"AADSTS90014":请求正文必须包含以下参数:'grant_type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将OneDrive for Busines集成到Web Form应用程序中. 为此,我正在使用此URL上给出的文档 dev.onedrive/auth/aad_oauth.htm 在Web Form App中,我有两个页面 第一个是登录页面,其中有一个用于登录的按钮 在按钮登录中,单击我正在使用以下代码向OneDrive for Business API发出GET请求

I m trying to integrate the OneDrive for Busines to a Web Form App. For this i am using the documentation given at this url dev.onedrive/auth/aad_oauth.htm In web Form App I have two Page First one is Login page which have a button for login In button login click i am making a GET Request to OneDrive for Business API using the following code

HttpClient client = new HttpClient(); Redirecturi = Uri.EscapeDataString(Redirecturi); string url = string.Format("login.windows/common/oauth2/authorize?response_type=code&client_id={0}&redirect_uri={1}", ClienId, Redirecturi); var response = client.GetAsync(url); var json = response.Result.Content.ReadAsStringAsync(); Label2.Text = json.Result;

当我单击登录按钮时,它将带我去micorosoft登录服务,然后将我发送回带访问代码的callback.aspx页面(在Azure上配置了重定向URi)

When I Click on login button it is taking me to micorosoft login servie and sending me back to callback.aspx page with access code (Redirect URi configured on azure)

我获得了访问代码 在第二页上,我正在兑换访问代码并发出POST请求以获取身份验证令牌 这是第二页的代码.

I got the access code On second page i am redeeming the access code and making a POST request to get the Authentication token Here is the code for the second page.

private string BaseUri="login.windows/common/oauth2/token"; public string Redirecturi = "localhost:51642/CallBack.aspx"; public string ResourcesId = "api.office/discovery/"; private string ClienId = "180c6ac4-5829-468e-.....-822405804862"; ///truncated//azure private string ClientSecert = "G4TAQzD8d7C4...OE6m366afv8XKbTCcyXr4=";//truncated protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString[OAuthConstants.AccessToken])) { // There is a token available already. It should be the token flow. Ignore it. return; } if (!string.IsNullOrEmpty(Request.QueryString[OAuthConstants.Code])) { string _accessCode = Request.QueryString[OAuthConstants.Code]; HttpClient client = new HttpClient(); // BaseUri = Uri.EscapeDataString(BaseUri); Redirecturi = Uri.EscapeDataString(Redirecturi); ResourcesId = Uri.EscapeDataString(ResourcesId); string url = string.Format("{0}?client_id={1}&redirect_uri={2}&grant_type=authorization_code&client_secret={3}&code={4}&grant_type=authorization_code&resource={5}", BaseUri, ClienId, Redirecturi, ClientSecert, _accessCode, ResourcesId); var response = client.PostAsync(url, null); var json = response.Result.Content.ReadAsStringAsync(); Response.Write(json); } }

但是我没有得到响应,而是出现以下错误.其中说在URL中包含grant_type.我已经添加了(您可以签入代码). 不包括此错误,我也会遇到相同的错误.

But instead of Response i am getting following error. Which say include the grant_type in url. I already added (u can check in code). Without including this also i am getting same error.

这是错误

{"error":"invalid_request","error_description":"AADSTS90014: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 2adb3a7f-ceb1-4978-97c4-3dc2d3cc3ad4\r\nCorrelation ID: 29fb11a0-c602-4891-9299-b0b538d75b5f\r\nTimestamp: 2015-07-15 09:58:42Z","error_codes":[90014],"timestamp":"2015-07-15 09:58:42Z","trace_id":"2adb3a7f-ceb1-4978-97c4-3dc2d3cc3ad4","correlation_id":"29fb11a0-c602-4891-9299-b0b538d75b5f","submit_url":null,"context":null}

请帮助了解哪里出了什么问题. 任何形式的帮助都将是可贵的 提前谢谢

please help to know where , what geting wrong. Any kind of help will be appreciable Thanks a lot in advance

推荐答案

您正在将参数添加到请求查询字符串中.您必须将数据发布到请求正文中.

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();

更多推荐

OneDrive for Business:"invalid

本文发布于:2023-11-26 23:36:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635673.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Business   OneDrive   invalid   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!