如何使用摘要身份验证在MongoDB Atlas API上进行身份验证?

时间:2019-09-20 07:33:24

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

我想使用其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'
  }
}  

有人可以帮我吗?

1 个答案:

答案 0 :(得分:2)

您所缺少的是键“立即发送”。您需要按如下所示在auth对象中发送它:

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