我正在尝试将AD v2 Oath授权代码流用于一个驱动器。 应用程序在我的帐户中作为Web平台正确注册。 我能够检索授权代码,但是当我要使用它以获取令牌时,我总是
{
"error": "invalid_grant",
"error_description": "AADSTS70000: The provided value for the 'code' parameter is not valid. The code has expired.\r\nTrace ID: 95d076f5-6cfa-4de1-ba1a-a81066cf1200\r\nCorrelation ID: 4cddfa50-228b-431a-8746-483e77a273e1\r\nTimestamp: 2017-06-10 09:50:38Z",
"error_codes": [
70000
],
"timestamp": "2017-06-10 09:50:38Z",
"trace_id": "95d076f5-6cfa-4de1-ba1a-a81066cf1200",
"correlation_id": "4cddfa50-228b-431a-8746-483e77a273e1"
}
我的要求
Dim url As New System.Text.StringBuilder
url.Append("grant_type=authorization_code")
url.Append("&client_id=" + clientid)
url.Append("&client_secret=" + clientsecret)
url.Append("&redirect_uri=" + System.Web.HttpUtility.UrlEncode(redirecturl))
url.Append("&code=" + authcode)
url.Append("&scope=" + ("offline_access%20files.readwrite"))
Dim baseaddress = "https://login.microsoftonline.com/common/oauth2/v2.0/token"
Dim buffer As Byte() = System.Text.Encoding.ASCII.GetBytes(url.ToString)
Dim req = Net.HttpWebRequest.Create(baseaddress)
req.Proxy = Nothing
req.Method = "Post"
req.ContentType = "application/x-www-form-urlencoded"
Dim strm As System.IO.Stream = req.GetRequestStream()
strm.Write(buffer, 0, buffer.Length)
strm.Close()
Dim resp As System.Net.HttpWebResponse = req.GetResponse()
Dim response = New IO.StreamReader(resp.GetResponseStream, False).ReadToEnd
Return response
答案 0 :(得分:0)
错误在于重定向网址。我已经设置了生产URL,之后我将代码复制到localhost以调试令牌进程。当我将请求的重定向url更改为locahost工作就像一个魅力。我的意见是应该在他们的文档中提到(我从来没有像谷歌驱动器等其他API那样的问题)