I am trying to integrate OneDrive for Busines into a Web Form application. For this, I use the documentation provided at this URL https://dev.onedrive.com/auth/aad_oauth.htm In the Web Form application, I have two pages. The first is the login page, which has a button to enter system When I click on the login button, I make a GET request for OneDrive for business API using the following code
HttpClient client = new HttpClient(); Redirecturi = Uri.EscapeDataString(Redirecturi); string url = string.Format("https://login.windows.net/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;
When I press the login button, I take me to micorosoft support and send me back to the callback.aspx page with the access code (URi redirection is set to light blue)
I got the access code. On the second page, I can fix the access code and make a POST request to get the authentication token. Here is the code for the second page.
private string BaseUri="https://login.windows.net/common/oauth2/token"; public string Redirecturi = "http://localhost:51642/CallBack.aspx"; public string ResourcesId = "https://api.office.com/discovery/"; private string ClienId = "180c6ac4-5829-468e-.....-822405804862";
But instead of the answer, I get the following error. By the way, specify type grant_type in url. I already added (you can check the code). Without including this, I also get the same error.
Here is the 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 find out where, what happened wrong. Any help would be appreciated Thank you in advance