我认为您为检索访问令牌而修改的脚本没有错。请再次确认授权流程。
-
在添加应用程序
https://apps.dev.microsoft.com/
-
-
创建应用程序机密。
-
平台是web。在这种情况下,重定向URL为
http://localhost
-
从检索代码
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=### Application ID ###&scope=offline_access%20files.readwrite.all&response_type=code&redirect_uri=http://localhost
-
请将以上URL输入您的浏览器,并从重定向的URL中检索代码。
-
在这里,为了上传文件,它包括
files.readwrite.all
在范围内。
-
刷新令牌可以通过以下方式检索:
offline_access
-
运行以下脚本以检索访问令牌并刷新令牌。
脚本:
request.post({
url:'https://login.microsoftonline.com/common/oauth2/v2.0/token',
form: {
redirect_uri: 'http://localhost',
client_id: 'abf3247c-d56a-xxxxxxxxxxxxxxxxxxxxx',
client_secret: '3o6xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
code: 'M8aad1bcf-xxxxxxxxxxxxxxxxxxxxxxxxxx',
grant_type: 'authorization_code'
}
}, function(err,httpResponse,body){
console.log('body: ' + body)
});
{
"token_type": "Bearer",
"scope": "Files.ReadWrite.All",
"expires_in": 3600,
"ext_expi
res_in": 0,
"access_token": "#####",
"refresh_token": "#####"
}
如果这不是你的解决方案,我很抱歉。
用于从刷新令牌检索访问令牌的脚本:
request.post({
url:'https://login.microsoftonline.com/common/oauth2/v2.0/token',
form: {
redirect_uri: 'http://localhost',
client_id: 'abf3247c-d56a-xxxxxxxxxxxxxxxxxxxxx',
client_secret: '3o6xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
refresh_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
grant_type: 'refresh_token'
}
}, function(err,httpResponse,body){
console.log('body: ' + body)
});