【问题标题】:How to authenticate at MongoDB Atlas API using digest authentication?如何使用摘要身份验证在 MongoDB Atlas API 上进行身份验证?
【发布时间】:2020-01-21 05:49:17
【问题描述】:

我想使用 MongoDB 的 API“https://cloud.mongodb.com/api/atlas/v1.0/groups”获取 MongoDB 中的项目列表,但每次我收到“401 您无权使用此资源”的错误。

根据docs使用摘要认证。

好像我以错误的方式传递 Private_key 和 Public_key。

下面是我的请求对象

{
url: 'https://cloud.mongodb.com/api/atlas/v1.0/groups',
method: 'GET',
headers: {
  'Accept': 'application/json',
},
auth: {
  user: 'Public_Key',
  pass: 'Private_key'
  }
}  

谁能帮帮我。

【问题讨论】:

  • docs.atlas.mongodb.com/reference/api/project-get-all MongoDB 的上述 API 链接说使用 Private_key 和 Public_key 进行身份验证,但我是否以正确的方式使用它仍然感到困惑。
  • 感谢您的链接。我稍微改写了问题以使其更清晰,并添加了链接。所以这是摘要认证。我不能马上回答,但是有一个example on wikipedia。您在来自服务器的 401 响应中获得了 nonce 和其他一些值,并且需要使用 MD5 哈希计算您的响应值。
  • 您也可以点击digest authentication标签查看其他问题和答案,其中一些还包含代码示例,可能有助于获得想法。

标签: node.js mongodb authentication digest-authentication mongodb-atlas


【解决方案1】:

您缺少的是“sendImmediately”键。您需要将其发送到您的身份验证对象中,如下所示:

   request({
       method: 'GET',
       auth: {
       "user": Public_Key,
       "pass": Private_key,
       "sendImmediately": false
   },
       url: 'https://cloud.mongodb.com/api/atlas/v1.0?pretty=true'
   })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    相关资源
    最近更新 更多