【发布时间】:2017-08-02 10:35:52
【问题描述】:
大家好,我想创建对我的 onedrive 帐户的访问权限,以便从我的家用电脑窗口通过 node.js 上传文件。
我在https://apps.dev.microsoft.com创建了一个应用程序
我还在那里创建了一个客户端密码并添加了一个 Web 平台并将重定向 url 从 localhost 更改为 https://login.live.com/oauth20_desktop.srf
然后我在浏览器中使用了这个链接 https://login.live.com/oauth20_authorize.srf?client_id=ab82982b-4dxxxxxxxxxxxxxxxxx&scope=files.readwrite.all&response_type=code
我浏览器中的 URL 更改为 https://login.live.com/oauth20_desktop.srf?code=M494a5b9fxxxxxxxxxxxxxxxxxxxxxxx&lc=1031
然后我发出一个 POST 请求,就像他们在 https://dev.onedrive.com/auth/graph_oauth.htm 上所说的那样
与
request({
uri: "https://login.microsoftonline.com/common/oauth2/v2.0/token?"
+ "&client_id=ab82982b-4dbe-4c6b-a1fe-2d60d01709fd&"
+ "client_secret=TkYZhYyuEiSoqhCxbh4Dqh3"
+ "&code=M494a5b9f-5577-3454-a78c-cef649a512c0"
+ "&grant_type=authorization_code",
method: "POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}, function(error, response, body) {
console.log('body: ', body);
});
但是输出是
body: {"error":"invalid_request","error_description":"AADSTS90014: The
request body must contain the following parameter: 'grant_type'.\r\nTrace
ID:
de2c2dxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\nCorrelation ID:
de2f8b83xxxxxxxxxxxxxxxxxxxxxxxxx\r\nTimestamp: 2017-07-31 13:40:52Z","error_codes":[90014]
,"timestamp":"2017-07-31 13:40:52Z","trace_id":"de2c2da2xxxxxxxxxxxxxxxxxxx","correlation_id":"de2f8b8xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
请帮助我在这个 API 令牌的东西上苦苦挣扎..
从下面的评论编辑我也改变了
request.post({url:'https://login.microsoftonline.com/common/oauth2/v2.0/token', form: {
redirect_uri: 'https://login.live.com/oauth20_desktop.srf',
client_id: 'abf3247c-d56a-xxxxxxxxxxxxxxxxxxxxx',
client_secret: '3o6xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
code: 'M8aad1bcf-xxxxxxxxxxxxxxxxxxxxxxxxxx',
grant_type: 'authorization_code'
}
}, function(err,httpResponse,body){ /* ... */
console.log('err: ' + err)
console.log('body: ' + body)
})
但现在我得到 "error":"invalid_request","error_description":"AADSTS90023: Public clients can't send a client secret。
我在谷歌上搜索并读到我无法使用桌面应用程序发出客户端秘密请求。但我在https://apps.dev.microsoft.com 创建了一个网络应用程序
此外,我从请求中删除了客户端密码,我收到重定向 url 错误的错误消息。请发给我工作代码示例,我现在为此苦苦挣扎了好几天..
这太难了啊啊啊啊啊啊啊啊啊啊啊啊啊啊:D请帮忙
【问题讨论】:
-
尝试使用额外的
form参数发送请求?我不确定request模块是否会自动解析 URI。使用 url 编码形式的示例见here -
啊我想我知道你的意思我会尝试