无法生成访问令牌和刷新令牌

时间:2020-04-27 14:26:51

标签: azure-active-directory onedrive

我正在尝试对OneDrive执行文件传输自动化。为此,我需要从Microsoft_AAD_RegisteredApps生成访问令牌和刷新令牌。但是,我已经成功完成了前面的所有步骤。

以下是我的POST请求

POST /common/oauth2/v2.0/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 119

grant_type=authorization_code&client_id=XXXXXXXXXXXXXXXXXXXXX&code=XXXXXXXXXXXXXXXX
```. 
client_id -> Client ID generated from the APP
code -> Code generated by the below url

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=your_app_client_id&response_type=code&redirect_uri=https%3A%2F%2Flogin.microsoftonline.com%2Fcommon%2Foauth2%2Fnativeclient&response_mode=query&scope=User.Read%20offline_access%20Files.ReadWrite

Unfortunately I'm getting 404  always as response. May I know what is missing my code or I miss any certification or license. Anyway please help me to find out the issue 


1 个答案:

答案 0 :(得分:0)

似乎缺少一些参数,例如scoperedirect_uriclient_secret,但是我没有重现您的问题。因此,我提供了请求的详细信息,以供您参考,在我的测试中,请求成功。

enter image description here

有关授权码流程的更多信息,您可以参考此tutorial

顺便说一句,您的请求似乎有一些小问题。我注意到您提出了另外一个post。根据该帖子中的信息,我认为您可能需要检查Content-Type是否正确,即使您使用了post方法,您似乎也将参数放在查询URL中并跟在请求URL后面。您可能需要将参数放在请求正文中,而不是查询URL中。如果将它们放在查询URL中,然后放在请求URL中,则它们不会在后端代码中检索到。后端代码将首先检索参数grant_type,因此它将始终显示must contain grant_type错误。

希望有帮助〜