OneDrive代码流公共客户端无法发送客户端密钥 - Node.js

时间:2017-07-30 21:25:12

标签: node.js onedrive

嘿伙计我想创建对我的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

我的浏览器中的网址已更改为https://login.live.com/oauth20_desktop.srf?code=M494a5b9fxxxxxxxxxxxxxxxxxxxxxxx&lc=1031

然后我按照他们在https://dev.onedrive.com/auth/graph_oauth.htm

上的说法发出了一个POST请求

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)
})

但现在我得到"错误":" invalid_request"," error_description":" AADSTS90023:公共客户端无法发送客户端秘密。

我谷歌这一点,并读到我无法通过桌面应用程序发出客户端秘密请求。但我在https://apps.dev.microsoft.com

创建了一个Web应用程序

此外,我从请求中删除了客户端密码,我收到重定向网址错误的错误。请发给我工作代码示例我现在已经好几天了......

这是如此困难aaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhh:D请帮助

1 个答案:

答案 0 :(得分:0)

你的问题已经打开了吗?您似乎想要检索访问令牌和刷新令牌。如果我误解了你的问题,我很抱歉。

我认为您修改的用于检索访问令牌的脚本没有错。请再次确认授权流程。

  1. https://apps.dev.microsoft.com/
  2. 添加申请
  3. 输入应用程序名称。在这种情况下,请勿使用Guided Setup
  4. 创建应用程序密钥。
  5. 平台是网络。在这种情况下,重定向网址为http://localhost
  6. 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检索代码
    • 请将以上网址输入您的浏览器,然后从重定向的网址中检索代码。
    • 此处,为了上传文件,它在范围内包含files.readwrite.all
    • 可以通过将offline_access包含在范围内来检索刷新令牌。
  7. 运行以下脚本以检索访问令牌和刷新令牌。
  8. 脚本:

    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)
    });
    
相关问题