You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Jens Alfke <je...@couchbase.com> on 2012/05/19 02:54:51 UTC
How does OAuth support, or custom headers, work in the replicator?
There's a small bit in the wiki* that hints at a replication JSON parameter to set custom headers. One of the examples of a _replicate request shows the body:
> {"source":{"url":"https://example.net:5984/db","headers":{"Authorization":"Basic Ym9iQGV4YW1wbGUuY29tOnBhc3N3b3Jk"}}, "target":"local-db"}
There's no further explanation; could someone clarify whether the 'headers' property can be used to add arbitrary HTTP headers to the requests sent by the replicator?
A few paragraphs later is the statement:
> Using a JSON hash (instead of a plain string) may also be used to specify OAuth (by adding a "oauth" field to the hash).
I don't understand this at all ('oauth' isn't an HTTP header, so does this mean to add it as a top-level property in the _replicate body? Or somewhere else? And what should its contents be?
I'd like to know how OAuth is used to authenticate to CouchDB, but there's almost nothing about it in the wiki.
—Jens
* http://wiki.apache.org/couchdb/Replication
Re: How does OAuth support, or custom headers, work in the replicator?
Posted by Martin Higham <ma...@ocasta.co.uk>.
http://hueniverse.com/oauth/guide/authentication/
Here's how the secrets and tokens map to the terms in the article:
OAuth Client token & secret -> couchDB OAuth Consumer key & consumer Secret
OAuth Access token & token secret -> couchDB Token & token secret
Signature method is pretty much always HMAC-SHA1
On Monday, 21 May 2012, Jens Alfke wrote:
>
> On May 20, 2012, at 4:02 AM, Martin Higham wrote:
>
> > - The fields in the replication structure are fine if you want CouchDB to
> > replicate to CouchDB, but I think in your case you want to OAuth requests
> > from a client to CouchDB so you will want to sign each request yourself.
>
> Not quite: I'm implementing what is effectively a client-side CouchDB
> server*. It has its own replicator, which may need to authenticate to the
> remote server it's replicating with. I'm trying to implement OAuth for
> that. So it's actually a combination of the two — the replicator obviously
> acts as a client to the remote server, but TouchDB implements most of the
> CouchDB REST API for the local app to interact with, and that extends to
> the schema of replication documents.
>
> So I think my new question is: Given the fields "consumer_secret",
> "consumer_key", "token_secret", "token" and "signature_method", how do I
> use them to sign a request? I'm an OAuth dummy but fairly knowledgeable
> about security/crypto, so a link to the right spec or section thereof would
> suffice :)
>
> —Jens
>
> * https://github.com/couchbaselabs/TouchDB-iOS
Re: How does OAuth support, or custom headers, work in the
replicator?
Posted by Jens Alfke <je...@couchbase.com>.
On May 20, 2012, at 4:02 AM, Martin Higham wrote:
> - The fields in the replication structure are fine if you want CouchDB to
> replicate to CouchDB, but I think in your case you want to OAuth requests
> from a client to CouchDB so you will want to sign each request yourself.
Not quite: I'm implementing what is effectively a client-side CouchDB server*. It has its own replicator, which may need to authenticate to the remote server it's replicating with. I'm trying to implement OAuth for that. So it's actually a combination of the two — the replicator obviously acts as a client to the remote server, but TouchDB implements most of the CouchDB REST API for the local app to interact with, and that extends to the schema of replication documents.
So I think my new question is: Given the fields "consumer_secret", "consumer_key", "token_secret", "token" and "signature_method", how do I use them to sign a request? I'm an OAuth dummy but fairly knowledgeable about security/crypto, so a link to the right spec or section thereof would suffice :)
—Jens
* https://github.com/couchbaselabs/TouchDB-iOS
Re: How does OAuth support, or custom headers, work in the replicator?
Posted by Martin Higham <ma...@ocasta.co.uk>.
Hi Jens,
- CouchDB supports OAuth 1.0, not 2.0
- The fields in the replication structure are fine if you want CouchDB to
replicate to CouchDB, but I think in your case you want to OAuth requests
from a client to CouchDB so you will want to sign each request yourself.
- We use the OAuthConsumer library to authenticate requests fromIOS to
CouchDB. Our fork (https://github.com/ocastastudios/oauthconsumer) has a
some bug fixes as the library creator doesn't seem to be maintaining it.
- The CouchDB wiki contains the details on configuring OAuth on the server (
http://wiki.apache.org/couchdb/Link_Collection_Authentication_and_Authorization
)
- CouchDB doesn't give you any way to get the tokens from the server to the
client so this has to be application specific.
Martin
On 19 May 2012 19:59, Jens Alfke <je...@couchbase.com> wrote:
>
> On May 18, 2012, at 6:05 PM, Adam Kocoloski wrote:
>
> > I had to read the code for this one. It looks like e.g.
> source.auth.oauth would be a JSON object with "consumer_secret",
> "consumer_key", "token_secret", and "token" fields (and an optional
> "signature_method" field). The Authorization header would be computed by
> the replicator for each request using this information.
>
> Does anyone here know more about OAuth? I'm implementing the MAC
> authorization scheme* that OAuth uses, but the parameters it takes don't
> seem to match up with what's listed above. The parameters I need to compute
> the Authorization header are {key, key identifier, issue time}.
>
> (This is for the purpose of implementing OAuth support in TouchDB, by the
> way.)
>
> —Jens
>
> * http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-00
>
>
Re: How does OAuth support, or custom headers, work in the
replicator?
Posted by Jens Alfke <je...@couchbase.com>.
On May 18, 2012, at 6:05 PM, Adam Kocoloski wrote:
> I had to read the code for this one. It looks like e.g. source.auth.oauth would be a JSON object with "consumer_secret", "consumer_key", "token_secret", and "token" fields (and an optional "signature_method" field). The Authorization header would be computed by the replicator for each request using this information.
Does anyone here know more about OAuth? I'm implementing the MAC authorization scheme* that OAuth uses, but the parameters it takes don't seem to match up with what's listed above. The parameters I need to compute the Authorization header are {key, key identifier, issue time}.
(This is for the purpose of implementing OAuth support in TouchDB, by the way.)
—Jens
* http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-00
Re: How does OAuth support, or custom headers, work in the replicator?
Posted by Filipe David Manana <fd...@apache.org>.
Ultimate source of truth, the test suite:
https://github.com/apache/couchdb/blob/1.2.0/share/www/script/test/oauth.js#L75
It's (source | target).auth.oauth.(consumer_key | consumer_secret |
token | token_secret)
On Mon, May 21, 2012 at 10:43 PM, Jens Alfke <je...@couchbase.com> wrote:
>
> On May 21, 2012, at 2:28 PM, Jim Klo wrote:
>> I'm a bit confused though by your statement Adam (and maybe I'm being a bit naive), but that doesn't quite jive with me..
>> is the resultant replicator doc something like this?
>
> My understanding is that it looks like this:
>
> {
> "source": "widgets",
> "target": {
> "url": "https://www.example.com/couchdb/widgets",
> "oauth": {
> "consumer_secret": "...",
> "consumer_key": "...",
> "token_secret": "...",
> "token": "....",
> "signature_method": "…"
>
> The "source" or "target" property can optionally be an object with the URL in a "url" property, instead of just a string. This allows extra metadata, like headers or auth, to be added to it.
>
> However, Adam says "It looks like e.g. source.auth.oauth would be a JSON object…" whereas the Replication page on the wiki says to add the "oauth" key directly to the source or target object. I illustrated the latter above, but I'm not sure which is correct.
>
> —Jens
--
Filipe David Manana,
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."
Re: How does OAuth support, or custom headers, work in the
replicator?
Posted by Jens Alfke <je...@couchbase.com>.
On May 21, 2012, at 2:28 PM, Jim Klo wrote:
> I'm a bit confused though by your statement Adam (and maybe I'm being a bit naive), but that doesn't quite jive with me..
> is the resultant replicator doc something like this?
My understanding is that it looks like this:
{
"source": "widgets",
"target": {
"url": "https://www.example.com/couchdb/widgets",
"oauth": {
"consumer_secret": "...",
"consumer_key": "...",
"token_secret": "...",
"token": "....",
"signature_method": "…"
The "source" or "target" property can optionally be an object with the URL in a "url" property, instead of just a string. This allows extra metadata, like headers or auth, to be added to it.
However, Adam says "It looks like e.g. source.auth.oauth would be a JSON object…" whereas the Replication page on the wiki says to add the "oauth" key directly to the source or target object. I illustrated the latter above, but I'm not sure which is correct.
—Jens
Re: How does OAuth support, or custom headers, work in the
replicator?
Posted by Jim Klo <ji...@sri.com>.
I'm trying to figure this OAuth bit out too.
I'm a bit confused though by your statement Adam (and maybe I'm being a bit naive), but that doesn't quite jive with me..
is the resultant replicator doc something like this?
{
"source": "widgets",
"target": "https://www.example.com/couchdb/widgets",
"oauth": {
"consumer_secret": "...",
"consumer_key": "...",
"token_secret": "...",
"token": "....",
"signature_method": "..."
}
}
or is it?
{
"source": "widgets",
"target": {
"what field is this?": "https://www.example.com/couchdb/widgets",
"auth": {
"oauth": {
"consumer_secret": "...",
"consumer_key": "...",
"token_secret": "...",
"token": "....",
"signature_method": "..."
}
}
}
}
If the latter is correct; what's the key name for specifying the url for the db?
if it's the former, is oauth only used on the 'remote' endpoint whether it's source or target?
or am I just way off base?
Thanks,
Jim Klo
Senior Software Engineer
Center for Software Engineering
SRI International
On May 18, 2012, at 6:05 PM, Adam Kocoloski wrote:
> On May 18, 2012, at 8:54 PM, Jens Alfke wrote:
>
>> There's a small bit in the wiki* that hints at a replication JSON parameter to set custom headers. One of the examples of a _replicate request shows the body:
>>
>>> {"source":{"url":"https://example.net:5984/db","headers":{"Authorization":"Basic Ym9iQGV4YW1wbGUuY29tOnBhc3N3b3Jk"}}, "target":"local-db"}
>>
>> There's no further explanation; could someone clarify whether the 'headers' property can be used to add arbitrary HTTP headers to the requests sent by the replicator?
>
> Yepper, that's all there is to it.
>
>> A few paragraphs later is the statement:
>>
>>> Using a JSON hash (instead of a plain string) may also be used to specify OAuth (by adding a "oauth" field to the hash).
>>
>> I don't understand this at all ('oauth' isn't an HTTP header, so does this mean to add it as a top-level property in the _replicate body? Or somewhere else? And what should its contents be?
>>
>> I'd like to know how OAuth is used to authenticate to CouchDB, but there's almost nothing about it in the wiki.
>
> I had to read the code for this one. It looks like e.g. source.auth.oauth would be a JSON object with "consumer_secret", "consumer_key", "token_secret", and "token" fields (and an optional "signature_method" field). The Authorization header would be computed by the replicator for each request using this information. I'm no OAuth expert, though. Cheers,
>
> Adam
>
>> —Jens
>>
>> * http://wiki.apache.org/couchdb/Replication
>
Re: How does OAuth support, or custom headers, work in the
replicator?
Posted by Jens Alfke <je...@couchbase.com>.
On May 18, 2012, at 6:05 PM, Adam Kocoloski wrote:
> I had to read the code for this one. It looks like e.g. source.auth.oauth would be a JSON object with "consumer_secret", "consumer_key", "token_secret", and "token" fields (and an optional "signature_method" field). The Authorization header would be computed by the replicator for each request using this information. I'm no OAuth expert, though.
Thanks! I've updated the wiki page with the info.
—Jens
Re: How does OAuth support, or custom headers, work in the replicator?
Posted by Adam Kocoloski <ko...@apache.org>.
On May 18, 2012, at 8:54 PM, Jens Alfke wrote:
> There's a small bit in the wiki* that hints at a replication JSON parameter to set custom headers. One of the examples of a _replicate request shows the body:
>
>> {"source":{"url":"https://example.net:5984/db","headers":{"Authorization":"Basic Ym9iQGV4YW1wbGUuY29tOnBhc3N3b3Jk"}}, "target":"local-db"}
>
> There's no further explanation; could someone clarify whether the 'headers' property can be used to add arbitrary HTTP headers to the requests sent by the replicator?
Yepper, that's all there is to it.
> A few paragraphs later is the statement:
>
>> Using a JSON hash (instead of a plain string) may also be used to specify OAuth (by adding a "oauth" field to the hash).
>
> I don't understand this at all ('oauth' isn't an HTTP header, so does this mean to add it as a top-level property in the _replicate body? Or somewhere else? And what should its contents be?
>
> I'd like to know how OAuth is used to authenticate to CouchDB, but there's almost nothing about it in the wiki.
I had to read the code for this one. It looks like e.g. source.auth.oauth would be a JSON object with "consumer_secret", "consumer_key", "token_secret", and "token" fields (and an optional "signature_method" field). The Authorization header would be computed by the replicator for each request using this information. I'm no OAuth expert, though. Cheers,
Adam
> —Jens
>
> * http://wiki.apache.org/couchdb/Replication