I have a reasonable bit of programming experience but I'm still very new to RavenDB, and since much of my programming experience is in PHP, I thought 'Why not get a handle on this NoSQL stuff by integrating it into what you know?'
I'm wondering how many other people are trying to do this, information about it is quite difficult to find (Mostly because of how difficult it is to get Google to tell the difference between 'POST requests' and 'Forum posts'... not to mention any page with a php url shows up ;-) )
Single page requests are easy (file_get_contents... it's all in the url afterall) but my first time trying to do a POST to query for multiple documents resulted in quite a bit of head scratching, research and then finally producing... something that didn't work :-P
So if anyone's got any advice I'd love to hear it, links to examples or tutorials would be brilliant, but if not... hey, i might be able to help expand the Knowledge base a tiny bit.
My Understanding so far (presumably wrong) is:
> curl -X POST http://localhost:8080/queries -d"['users/ayende','users/oren']"
should equate to something like:
$json = "['users/ayende','users/oren']";
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Accept: application/json',
'content' => $json
)
);
$context = stream_context_create($opts);
$response = file_get_contents("http://localhost:8080/queries", false, $context);
...Or are streams different? If so am I going to have to get the cURL library for PHP then?
You could use RavenDB over HTTP directly from your application. No need to use cURL.The best documentation is the HTTP API documentation of RavenDB.
You probably want to look at this?I have done very little with php but that post helped me back in the days ;)
If you are not doing any authorization, perhaps you need to set: <add key="Raven/AnonymousAccess" value="All"/>
Keep in mind, that opens you up completely to anyone querying Raven.
if the user agent uses 'Aladin' as the username and 'sesam open' as the password then the header is formed as follows:Authorization: Basic QWxhZGluOnNlc2FtIG9wZW4=
Authorization: Basic
Does anyone know which of these are even possible and possibly how they are done? :-\
What is the problem in using Windows Authentication?
RavenDB is running on Windows (I guess) thus you only need to specify in the connection string you are using to connect to the server a valid Windows user & password that the server can use to authenticate the incoming request.
.m
you only need to specify in the connection string you are using
Can you use the oauth provider in rdb?
How does OAuth work?
In order to add a user we can use the following code:
using(var session = documentStore.OpenSession()){session.Store(new AuthenticationUser{Name = "Ayende",Id = "Raven/Users/Ayende",AllowedDatabases = new[] {"*"}}.SetPassword("abc"));session.SaveChanges();}If no users are found on the database a user "admin" will be created with an auto generated password. This data can be viewed in the "authentication.config" file.
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="Raven", error="invalid_request",error_description="The access token is required"
Server: Microsoft-HTTPAPI/1.0
OAuth-Source: http://vserver1:8080/OAuth/AccessToken
Date: Mon, 24 Sep 2012 00:42:55 GMT
Connection: close
Content-Length: 0
{
"Name":"Ayende",
"Id":"Raven/Users/Ayende",
"Password":"123",
"AllowedDatabases":[{"*"}]
}
//After making a normal request which failedforeach ($http_response_header as $headerItem){if (substr($headerItem, 0, 5) == 'OAuth') $authURL = substr($headerItem, (strpos($headerItem, ":")+1));if (substr($headerItem, 0, 16) == 'WWW-Authenticate') $auth = true;if (($authURL != "") && ($auth == true)) break;}//Check that it is asking for authentication, if so, grab the URL we need to go to.if (($authURL == "") && ($auth == false)) throw new Exception("Problem with $url, $php_errormsg");else{$authPass = base64_encode($RAVEN_USER.":".$RAVEN_PASS);//Username and password... in this case "Ayende:123"
$opts = array('http' => array('method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded, Accept: application/json, Authorization: Basic '.$authPass,
'content' => $json));$context = stream_context_create($opts);
$fp = @fopen($authURL, 'rb', false, $context);error_log("Authentication Response is... ".print_r($http_response_header, true));die;}
I can't make any promises, I've used fiddler briefly but not had a lot of luck with it, but I will try tomorrow and hopefully I will have something useful for you :-)
--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
