我已经看过如何使用arangosh对数据库进行身份验证的示例,但我在文档中找不到有关如何通过http API进行身份验证的内容。这可能吗?它是这样的:
答案 0 :(得分:5)
好的,在Windows上使用Arango DB中的身份验证后,我发现了这一点:
我无法使用此命令(应启用身份验证)
--server.disable-authentication false
更新:我意识到我无法使用此命令,因为它根本不是命令:-o在仔细查看文档后,它是一个命令行选项。它应该在你开始arangosh时使用。请参阅documentation here。
我认为我需要以某种方式调整它以在Windows命令提示符下工作,但我不确定需要更改什么。作为一个解决方法我打开文件“arangod.conf”(我发现它在这里C:\ Program Files(x86)\ ArangoDB 1.4.7 \ etc \ arangodb)并更改了以下行:
disable-authentication = yes
到
disable-authentication = no
当我重新启动Arango时启用了身份验证。耶!
现在通过http进行身份验证...非常简单。它只是基本的HTTP身份验证。所以在我的情况下,我使用NodeJS和请求库进行身份验证。以下两个例子都可以正常工作。
附加.auth的凭证:
request({
url:'http://localhost:8529/_api/document/example/20214484',
json: true
}, function (err, data){
console.log(err);
if (data.body.error) console.log("ERROR: " + data.body.errorMessage);
console.log(data.body);
}).auth("username", "password");
或使用网址中的凭据:
request({
url:'http://username:password@localhost:8529/_api/document/example/20214484',
json: true
}, function (err, data){
console.log(err);
if (data.body.error) console.log("ERROR: " + data.body.errorMessage);
console.log(data.body);
});
答案 1 :(得分:4)
从命令行,您可以执行类似的操作,将HTTP基本身份验证传递给服务器:
curl --basic --user "username:passwd" -X GET http://arangouri.com:8529/_api/document/...
以上示例适用于卷曲。如果您使用任何其他HTTP客户端,则必须找到用于设置HTTP基本身份验证的用户名/密码的选项,并将它们发送到服务器。
答案 2 :(得分:2)
通过Authorization
标头完成,您可以在其中设置身份验证机制(例如Basic),然后是格式为[username]:[password]
的base64编码字符串。可以找到更多信息,例如here。