denodrivers / mongo

🍃 MongoDB driver for Deno 🦕
https://deno.land/x/mongo
MIT License
509 stars 95 forks source link

Support authorization #129

Closed manyuanrong closed 3 years ago

manyuanrong commented 3 years ago

The current version using TS has more functions than before. However, authorized login has not yet been implemented. If completed, 1.0 can be released

https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#scram-sha-1

darrylsepeda commented 3 years ago

I'm curious, is this authorization is about this uri string: mongodb://user:pass@localhost:3000??

Preta-Crowz commented 3 years ago

I'm curious, is this authorization is about this uri string: mongodb://user:pass@localhost:3000??

I'm not sure but maybe current code will just connect to db without auth

darrylsepeda commented 3 years ago

I saw from here https://www.youtube.com/watch?v=VF38U2qd27Q, seems he can connect to mongo atlas, but somehow my mongo string to local mongodb doesn't work. How to establish connection to mongodb with user pass?

if this issue is related with that user pass, then I will wait while looking for a workaround.

manyuanrong commented 3 years ago

The version after v0.20.0 has completely used TS refactoring. Before that, it was packaged with mongodb's official rust library. Previous versions can work, but the plugin API of Deno itself is always in an unstable state, and it may be deleted. Therefore, this project has been completely rewritten and has not yet been able to support authorization. The work includes two parts

Preta-Crowz commented 3 years ago

//memo if authorization option was enabled on server, then server will throw this error: MongoError: {"ok":0,"errmsg":"command insert requires authentication","code":13,"codeName":"Unauthorized"}

hviana commented 3 years ago

Is ready my dear, my pull request is complete. The driver now supports authentication!

hviana commented 3 years ago

Pull request https://github.com/denodrivers/deno_mongo/pull/156

whiter001 commented 3 years ago

If the password contains a percent sign "%", it will be an error;
url like this "mongodb://abc:asdf%25@localhost:27017/test"; used v0.20.0 image

Preta-Crowz commented 3 years ago

@whiter001 already fixed on v0.20.1

manyuanrong commented 3 years ago

v0.21.0 is supported

darrylsepeda commented 3 years ago

I still got an error

Uncaught (in promise) Error: MongoError: {"ok":0,"errmsg":"Authentication failed.","code":18,"codeName":"AuthenticationFailed"}

while using the same string as being used in my mongodb compass. how to debug this?

darrylsepeda commented 3 years ago

and this is my code:

import { MongoClient } from "https://deno.land/x/mongo@v0.21.0/mod.ts";

const client = new MongoClient();
await client.connect(`mongodb://${user}:${pass}@localhost:27017/${db}`);
iamdenny commented 3 years ago

I have same error. image

my version is v0.21.0 and I tried to v0.21.2 also same.

iamdenny commented 3 years ago

my password is 123!%40%23. is it problem with special characters?

darrylsepeda commented 3 years ago

@iamdenny I don't think because of special characters, already tried using alphanumeric still doesn't work.

manyuanrong commented 3 years ago

@darrylsepeda You can try to use the parameter object to connect

await client.connect({
  credential:{
    username: `$username`,
    password: `${pass}`,
    mechanism: `SCRAM-SHA-1`,
    db: `$db`
  },
  db: `${db}`,
  servers: [{host:"localhost",port:27017}]
});
darrylsepeda commented 3 years ago

@manyuanrong thanks and noted, will try in a few days and let you know. cheers!