You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by CGS <cg...@gmail.com> on 2011/09/27 10:31:15 UTC

CouchDB cookie from outside CouchDB

Hi all,

I have few web applications which each requires login and I am trying to 
unify their login procedures. One of the applications is CouchDB 
(obviously) and, as far as I noticed, this application uses cookie 
system to save the login session. Does anyone know what JavaScript files 
I should load into the common login page and what to do to create that 
cookie?

I know there is an option to transfer the login session via address bar, 
but I do not fancy that option too much. That's why I try to create the 
cookie and I am trying to "hack" futon, but I would appreciate any help 
if any of you managed this before. Thank you.

Cheers,
CGS


Re: CouchDB cookie from outside CouchDB

Posted by CGS <cg...@gmail.com>.
Thanks, Dale. I will follow this suggestion (also Benoit suggested the 
same). I admit I didn't think of that before and both inputs are most 
appreciated.

Port 80 is handled by YAWS (required by the other applications because 
it's Erlang). In this moment I just need to update my YAWS version (I hope).

Thanks again to both of you for your support.

Cheers,
CGS



On 09/29/2011 10:11 PM, Dale Harvey wrote:
> how are you binding to port 80? if you have nginx / apache then you can have
> a reverse proxy, couch also has an in build reverse proxy built in, I would
> suggest going down that route before dealing with cross domain issues, there
> are a lot of them
>
> On 29 September 2011 17:45, Benoit Chesneau<bc...@gmail.com>  wrote:
>
>> On Thu, Sep 29, 2011 at 6:42 PM, CGS<cg...@gmail.com>  wrote:
>>> First of all, thank you Dale for your answer. Still, the problem is more
>>> complex than I anticipated.
>>>
>>> I am using YAWS as web server and it doesn't support proxy, so, I have to
>>> use two different ports for the two (CouchDB and YAWS). Methods I have
>>> tried:
>>> 1. $.ajax() - error: not allowed cross-domain data transfer via
>> JavaScript
>>> (both IP and port should match exactly for both origin and target), so,
>> even
>>> if correct authentication, no cookie.
>>> 2. form action pointing to
>>> server_name:5984/_session?next=/path_to_attachment/back.html - error: if
>> the
>>> authentication fails (incorrect username/password), the "next" is no
>> longer
>>> taken (back.html contains only window.location which redirects back to
>>> YAWS), but it goes back if the authentication doesn't fail.
>>>
>>> I would appreciate any idea related to how to solve any of these errors.
>>> Thank you.
>>>
>>> Cheers,
>>> CGS
>>>
>>>
>> can't you use the reverse proxy module of yaws ? Othere way would be
>> having an iframe. Waiting CORS (patch should be available on friday,
>> was busy).
>>
>> - benoit
>>


Re: CouchDB cookie from outside CouchDB

Posted by CGS <cg...@gmail.com>.
I used YAWS version 1.91 with reverse proxy and $.ajax() and now I have 
no problem to log in CouchDB from YAWS (and to remain in YAWS until 
different request is registered). Thank you both, Dale and Benoit, for 
your help.

Cheers,
CGS




On 09/29/2011 10:11 PM, Dale Harvey wrote:
> how are you binding to port 80? if you have nginx / apache then you can have
> a reverse proxy, couch also has an in build reverse proxy built in, I would
> suggest going down that route before dealing with cross domain issues, there
> are a lot of them
>
> On 29 September 2011 17:45, Benoit Chesneau<bc...@gmail.com>  wrote:
>
>> On Thu, Sep 29, 2011 at 6:42 PM, CGS<cg...@gmail.com>  wrote:
>>> First of all, thank you Dale for your answer. Still, the problem is more
>>> complex than I anticipated.
>>>
>>> I am using YAWS as web server and it doesn't support proxy, so, I have to
>>> use two different ports for the two (CouchDB and YAWS). Methods I have
>>> tried:
>>> 1. $.ajax() - error: not allowed cross-domain data transfer via
>> JavaScript
>>> (both IP and port should match exactly for both origin and target), so,
>> even
>>> if correct authentication, no cookie.
>>> 2. form action pointing to
>>> server_name:5984/_session?next=/path_to_attachment/back.html - error: if
>> the
>>> authentication fails (incorrect username/password), the "next" is no
>> longer
>>> taken (back.html contains only window.location which redirects back to
>>> YAWS), but it goes back if the authentication doesn't fail.
>>>
>>> I would appreciate any idea related to how to solve any of these errors.
>>> Thank you.
>>>
>>> Cheers,
>>> CGS
>>>
>>>
>> can't you use the reverse proxy module of yaws ? Othere way would be
>> having an iframe. Waiting CORS (patch should be available on friday,
>> was busy).
>>
>> - benoit
>>


Re: CouchDB cookie from outside CouchDB

Posted by Dale Harvey <da...@arandomurl.com>.
how are you binding to port 80? if you have nginx / apache then you can have
a reverse proxy, couch also has an in build reverse proxy built in, I would
suggest going down that route before dealing with cross domain issues, there
are a lot of them

On 29 September 2011 17:45, Benoit Chesneau <bc...@gmail.com> wrote:

> On Thu, Sep 29, 2011 at 6:42 PM, CGS <cg...@gmail.com> wrote:
> > First of all, thank you Dale for your answer. Still, the problem is more
> > complex than I anticipated.
> >
> > I am using YAWS as web server and it doesn't support proxy, so, I have to
> > use two different ports for the two (CouchDB and YAWS). Methods I have
> > tried:
> > 1. $.ajax() - error: not allowed cross-domain data transfer via
> JavaScript
> > (both IP and port should match exactly for both origin and target), so,
> even
> > if correct authentication, no cookie.
> > 2. form action pointing to
> > server_name:5984/_session?next=/path_to_attachment/back.html - error: if
> the
> > authentication fails (incorrect username/password), the "next" is no
> longer
> > taken (back.html contains only window.location which redirects back to
> > YAWS), but it goes back if the authentication doesn't fail.
> >
> > I would appreciate any idea related to how to solve any of these errors.
> > Thank you.
> >
> > Cheers,
> > CGS
> >
> >
> can't you use the reverse proxy module of yaws ? Othere way would be
> having an iframe. Waiting CORS (patch should be available on friday,
> was busy).
>
> - benoit
>

Re: CouchDB cookie from outside CouchDB

Posted by CGS <cg...@gmail.com>.
Thanks, Benoit. It might work this option, only that YAWS v.1.88 
(default for Ubuntu) is not able to handle revproxy (I get a nice 404). 
I think I need to install YAWS from github.

Cheers,
CGS





On 09/29/2011 06:45 PM, Benoit Chesneau wrote:
> On Thu, Sep 29, 2011 at 6:42 PM, CGS<cg...@gmail.com>  wrote:
>> First of all, thank you Dale for your answer. Still, the problem is more
>> complex than I anticipated.
>>
>> I am using YAWS as web server and it doesn't support proxy, so, I have to
>> use two different ports for the two (CouchDB and YAWS). Methods I have
>> tried:
>> 1. $.ajax() - error: not allowed cross-domain data transfer via JavaScript
>> (both IP and port should match exactly for both origin and target), so, even
>> if correct authentication, no cookie.
>> 2. form action pointing to
>> server_name:5984/_session?next=/path_to_attachment/back.html - error: if the
>> authentication fails (incorrect username/password), the "next" is no longer
>> taken (back.html contains only window.location which redirects back to
>> YAWS), but it goes back if the authentication doesn't fail.
>>
>> I would appreciate any idea related to how to solve any of these errors.
>> Thank you.
>>
>> Cheers,
>> CGS
>>
>>
> can't you use the reverse proxy module of yaws ? Othere way would be
> having an iframe. Waiting CORS (patch should be available on friday,
> was busy).
>
> - benoit


Re: CouchDB cookie from outside CouchDB

Posted by Benoit Chesneau <bc...@gmail.com>.
On Thu, Sep 29, 2011 at 6:42 PM, CGS <cg...@gmail.com> wrote:
> First of all, thank you Dale for your answer. Still, the problem is more
> complex than I anticipated.
>
> I am using YAWS as web server and it doesn't support proxy, so, I have to
> use two different ports for the two (CouchDB and YAWS). Methods I have
> tried:
> 1. $.ajax() - error: not allowed cross-domain data transfer via JavaScript
> (both IP and port should match exactly for both origin and target), so, even
> if correct authentication, no cookie.
> 2. form action pointing to
> server_name:5984/_session?next=/path_to_attachment/back.html - error: if the
> authentication fails (incorrect username/password), the "next" is no longer
> taken (back.html contains only window.location which redirects back to
> YAWS), but it goes back if the authentication doesn't fail.
>
> I would appreciate any idea related to how to solve any of these errors.
> Thank you.
>
> Cheers,
> CGS
>
>
can't you use the reverse proxy module of yaws ? Othere way would be
having an iframe. Waiting CORS (patch should be available on friday,
was busy).

- benoit

Re: CouchDB cookie from outside CouchDB

Posted by CGS <cg...@gmail.com>.
First of all, thank you Dale for your answer. Still, the problem is more 
complex than I anticipated.

I am using YAWS as web server and it doesn't support proxy, so, I have 
to use two different ports for the two (CouchDB and YAWS). Methods I 
have tried:
1. $.ajax() - error: not allowed cross-domain data transfer via 
JavaScript (both IP and port should match exactly for both origin and 
target), so, even if correct authentication, no cookie.
2. form action pointing to 
server_name:5984/_session?next=/path_to_attachment/back.html - error: if 
the authentication fails (incorrect username/password), the "next" is no 
longer taken (back.html contains only window.location which redirects 
back to YAWS), but it goes back if the authentication doesn't fail.

I would appreciate any idea related to how to solve any of these errors. 
Thank you.

Cheers,
CGS





On 09/27/2011 02:43 PM, Dale Harvey wrote:
> With Cookie authentication you send a POST to /_session and its result will
> contain a Set-Cookie (given the correct credentials), you dont need any
> special javascript around, just send the $_POST during login
>
> Cheers
> Dale
>
> On 27 September 2011 09:31, CGS<cg...@gmail.com>  wrote:
>
>> Hi all,
>>
>> I have few web applications which each requires login and I am trying to
>> unify their login procedures. One of the applications is CouchDB (obviously)
>> and, as far as I noticed, this application uses cookie system to save the
>> login session. Does anyone know what JavaScript files I should load into the
>> common login page and what to do to create that cookie?
>>
>> I know there is an option to transfer the login session via address bar,
>> but I do not fancy that option too much. That's why I try to create the
>> cookie and I am trying to "hack" futon, but I would appreciate any help if
>> any of you managed this before. Thank you.
>>
>> Cheers,
>> CGS
>>
>>


Re: CouchDB cookie from outside CouchDB

Posted by Dale Harvey <da...@arandomurl.com>.
With Cookie authentication you send a POST to /_session and its result will
contain a Set-Cookie (given the correct credentials), you dont need any
special javascript around, just send the $_POST during login

Cheers
Dale

On 27 September 2011 09:31, CGS <cg...@gmail.com> wrote:

> Hi all,
>
> I have few web applications which each requires login and I am trying to
> unify their login procedures. One of the applications is CouchDB (obviously)
> and, as far as I noticed, this application uses cookie system to save the
> login session. Does anyone know what JavaScript files I should load into the
> common login page and what to do to create that cookie?
>
> I know there is an option to transfer the login session via address bar,
> but I do not fancy that option too much. That's why I try to create the
> cookie and I am trying to "hack" futon, but I would appreciate any help if
> any of you managed this before. Thank you.
>
> Cheers,
> CGS
>
>