简体   繁体   English

通过HTTP进行ArangoDB身份验证

[英]ArangoDB authentication via HTTP

I've seen examples of how to authenticate with a database using arangosh, but I couldn't find anything in the documentation about how to authenticate via the http API. 我已经看到了如何使用arangosh对数据库进行身份验证的示例,但我在文档中找不到有关如何通过http API进行身份验证的内容。 Is this possible? 这可能吗? Is it something like this: 它是这样的:

http://username:passwd@arangouri.com:8529/_api/document HTTP://用户名:passwd@arangouri.com:8529 / _api /文件

Ok, after playing around with authentication in Arango DB on Windows here is what I have found: 好的,在Windows上使用Arango DB中的身份验证之后,我发现了以下内容:

I could not get this command to work (which is supposed to enable authentication) 我无法使用此命令(应该启用身份验证)

--server.disable-authentication false

UPDATE: I realized I couldn't get this command working because it's not a command at all :-o After looking more closely at the documentation it's a command line option. 更新:我意识到我无法使用此命令,因为它根本不是命令:-o在仔细查看文档后,它是一个命令行选项。 It should be used when you start arangosh. 它应该在你开始arangosh时使用。 See documentation here . 请参阅此处的文档

I assume I need to adapt it somehow to work in a windows command prompt, but I'm not sure what needs to change. 我假设我需要以某种方式调整它以在Windows命令提示符下工作,但我不确定需要更改什么。 As a work around I opened the file "arangod.conf" (I found it here C:\\Program Files (x86)\\ArangoDB 1.4.7\\etc\\arangodb) and changed the following line: 作为一个解决方法我打开文件“arangod.conf”(我在这里找到它C:\\ Program Files(x86)\\ ArangoDB 1.4.7 \\ etc \\ arangodb)并更改了以下行:

disable-authentication = yes

to

disable-authentication = no

This enabled authentication when I restarted Arango. 这在我重新启动Arango时启用了身份验证。 Yay! 好极了!

Now to authenticate via http... very simple. 现在通过http进行身份验证...非常简单。 It's just basic HTTP auth. 它只是基本的HTTP身份验证。 So in my case I was using NodeJS and the request library to authenticate. 所以在我的情况下,我使用NodeJS和请求库进行身份验证。 Both examples below work fine. 以下两个例子都可以。

Credentials appended with .auth: 附加.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");

OR with credentials in url: 或者使用url中的凭据:

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

From the command line, you can do something like this to pass HTTP basic authentication to the server: 从命令行,您可以执行以下操作以将HTTP基本身份验证传递到服务器:

curl --basic --user "username:passwd" -X GET http://arangouri.com:8529/_api/document/...

The above example is for curl. 以上示例适用于卷曲。 If you use any other HTTP client, you have to find the options for setting the username / password for HTTP basic authentication and send them to the server. 如果您使用任何其他HTTP客户端,则必须找到用于设置HTTP基本身份验证的用户名/密码的选项,并将它们发送到服务器。

It's done through Authorization header where you set authentication mechanism (eg Basic) followed by base64 encoded string in format [username]:[password] . 它通过Authorization标头完成,您可以在其中设置身份验证机制(例如Basic),然后是格式为[username]:[password] base64编码字符串。 More information can be found for example here . 例如,可以在此处找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM