通过本教程的第 4 部分调用 Microsoft Graph API 以获取访问 token :https://learn.microsoft.com/en-us/graph/auth-v2-service?view=graph-rest-1.0
我正在执行以下提取请求:
var options = {
"method": "POST",
"contentType": "application/x-www-form-urlencoded",
"accept": 'application/json',
"headers": {
'Content-Type': "application/x-www-form-urlencoded",
},
}
var authorization_url = "https://login.microsoftonline.com/" + tenant +
"/oauth2/v2.0/token/" +
"client_id=" + client_id +
"&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default" +
"&client_secret=" + client_secret +
"&grant_type=client_credentials";
相当有信心我的所有参数都是正确的,但它返回无效的请求错误:“请求正文必须包含以下参数:'grant_type'”。知道可能出了什么问题吗?
最佳答案
您的 authorization_url
应仅包含端点(即无查询字符串):
var authorization_url = "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token/"
参数属于POST
正文:
var payload =
"client_id=" + client_id +
"&client_secret=" + client_secret +
"&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default" +
"&grant_type=client_credentials";
(你的选项
对我来说看起来不错)
关于javascript - 尽管查询字符串中有 grant_type,Microsoft Graph API 返回 404 错误缺少参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54298914/