0

我想使用 Restify/Nodejs + Oauth2 + Mongodb 来注册和验证用户......我在这里找到了一个很棒的 git hub 存储库:

https://github.com/rgallagher27/node-restify-oauth2-mongodb

我同时安装了 Redis 和 Mongo,我使用代码启动并运行了节点,我可以注册用户。但是,我在验证用户时遇到了一些问题。说明中有一个步骤我不确定我是否正确完成...

//////////////////////
**Insert a Client Key into the mongoDB wit the format:** 

{
    _id: ObjectId("51c6e846ede91c0b8600005e"),
    clientName: "Test Client",
    client: "test",
    secret: "password"
}
//////////////////

这应该是一个mongo db,如

db.ClientKey.insert({_id: ObjectId("51c6e846ede91c0b8600005e"), clientName: "Test Client", client: "test",  secret: "password"});

或者这是一个集合?

我都试过了都没有用。

我相信我无法理解如何在 mongoDB 中创建它可能导致我无法验证用户的问题

在 mongodb 我的 restify_test 数据库有一个“用户”集合......它显示为

> db.users.find();
{
    "name" : "Test",  
    "email" : "test@test.com",
    "username" : "tester1", 
    "hashed_password" : "$2a$10$67rLfuKQqHIwHc2tOPNu.ejY.L/5Mk6XnuOdn0xc9UXUyzKBs6NQC",
    "_id" : ObjectId("520d5874421b580000000001"),
    "role" : "Admin", 
    "__v" : 0
}
> 

但是当我尝试卷曲登录时

$ curl --user test:password --data grant_type=password --data username=tester1 --data password=testing27 http://[my-localhost]:8090/token
{"error":"invalid_client","error_description":"Client ID and secret did not validate."}

我再次感谢您在这里给我的任何指导。

4

1 回答 1

1

使用此插入语句时,我遇到了与您完全相同的问题:

db.ClientKey.insert({_id: ObjectId("51c6e846ede91c0b8600005e"), clientName: "Test Client", client: "test",  secret: "password"});

我注意到的是,如果我确实在 mongo中显示集合,则一个集合称为users,另一个称为ClientKey。经过反复试验,我发现集合需要调用clientkeys(注意复数和小写)。您应该能够运行这些命令来解决问题(假设您正在从命令行工作):

mongo
use restify_test
db.ClientKey.renameCollection("clientkeys")

一旦我这样做了,执行 curl 命令就正确地返回了我的 access_token 和 token_type。

希望有帮助!

于 2013-10-05T07:06:46.720 回答