簡體   English   中英

使用node-restify-oauth2-mongodb時出現問題

[英]Problems using node-restify-oauth2-mongodb

我想使用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.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."}

我再次感謝您為我提供的任何指導。

使用此插入語句時,我遇到了與您完全相同的問題:

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

我注意到的是,如果我確實在mongo中顯示了集合 ,則一個集合稱為用戶 ,另一個集合稱為ClientKey 經過反復試驗,我得出了該集合需要調用clientkeys (注意復數和小寫字母)的信息。 您應該能夠運行以下命令來解決此問題(假設您正在通過命令行工作):

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

完成此操作后,正確執行curl命令將返回我的access_token和token_type。

希望有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM