使用 node-restify-oauth2-mongodb 的问题 [英] Problems using node-restify-oauth2-mongodb

查看:100
本文介绍了使用 node-restify-oauth2-mongodb 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to use Restify/Nodejs + Oauth2 + Mongodb to register and authenticate users... I found a great git hub repo here:

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

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

I have both Redis and Mongo installed and I get the node up and running with the code and I can register users. However, I have some problems with validating a user. There was one step in the instructions that I am not sure I am completing correctly ...

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

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

这应该是一个 mongo db 吗

Should this be a mongo db as in

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

或者这是一个集合?

我都试过都没有用.

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

I believe my failure to understand how this should be created in mongoDB may be causing my issues with an inability to validate a user

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

in mongodb my restify_test db has a "users" collections... which appears as

> 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
}
> 

但是当我尝试卷曲登录时

But when i try to curl the login

$ 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."}

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

Once again I thank you for any direction you can give me here.

推荐答案

我在使用这个插入语句时遇到了和你完全一样的问题:

I had the exact same problem as you when using this insert statement:

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

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

The thing that I noticed was the if I did show collections in mongo, one collections was called users and the other was ClientKey. With some trial and error I worked out that the collection needed to called clientkeys (note the plural and lowercase). You should be able to run these commands to fix the issue (assuming you're working from the command line):

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

执行此操作后,执行 curl 命令正确返回了我的 access_token 和 token_type.

Once I did this, executing the curl command correctly returned my access_token and token_type.

希望有帮助!

这篇关于使用 node-restify-oauth2-mongodb 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆