3

I am trying to link my nodejs app with my mongodb atlas cluster and I need to be able to add and delete users using the AtlasDB API. The API requires Digest authentication to access, and the api is very vague on how to actually write this header. Here is my current attempt:

export async function createUser(userData) {
const options = {
    roles: [
        {
            roleName: "readWrite",
            databaseName: process.env.MONGO_DBNAME
        }
    ]
}
const url = `${process.env.MONGO_API_BASEURL}/groups/${process.env.MONGO_PROJECT_ID}/databaseUsers`


const result = await axios({
    method: 'POST',
    url,
    headers: {'WWW-Authenticate': `Digest ${process.env.MONGO_USERNAME}:${process.env.MONGO_APIKEY}},
    data: {
        databaseName: "admin",
        username: userData.username,
        password: userData.password,
        roles: options.roles,
        groupId: process.env.MONGO_PROJECT_ID
    }
})

return result}

No surprise, I get a 401 response, which means that authentication failed. There is very little information out there on writing Digest Auth Header, and I am a bit confused on how to do it.

Any help will be greatly appreciated. Thanks!

SirWinning
  • 111
  • 8

0 Answers0