How to modify the docs by Sync Gateway REST APIs with SyncGatewaySession?

130 views
Skip to first unread message

atom992

unread,
Jun 27, 2015, 8:01:53 AM6/27/15
to mobile-c...@googlegroups.com
Hi,I want to know that how can I modify/get docs by SG REST APIs with SyncGatewaySession?
I can get docs by add Authorization header with Basic certificate of some user(this need name and password), but I want to do the same thing by SyncGatewaySession(Cookies), because I already get the user's certificate by Authentication REST APIs.
so I try the following tests:
curl  --cookie "SyncGatewaySession=2823i1826e9e2ad72af0409e0703f9bf1s9317d3" --header Content-Type:"application/json" http://127.0.0.1/sgdb/doc1
but I got the following errors:
{"error":"Unauthorized","reason":"Login required"}

ajres

unread,
Jun 27, 2015, 10:14:05 AM6/27/15
to mobile-c...@googlegroups.com
@atom992

I just ran the following against a clean Sync Gateway (master) DB with a user defined in config.json

```

"user1": {"disabled": false, "password":"passw0rd", "admin_channels": ["*"]}

```

Write a doc with basic auth
```

$ curl -X PUT  http://user1:passw0rd@localhost:4984/db/doc1 -d '{ "foo":"bar"}' -H 'Content-Type: application/json'

```

Create a users session via the ADMIN REST API

```

$ curl -X POST http://localhost:4985/db/_session -d '{ "name":"user1","password":"passw0rd"}' -H "Content-Type: application/json"

```

Response: {"session_id":"971106d126515e4e071ad05070ffc76627289c16","expires":"2015-06-28T14:51:10.961084691+01:00","cookie_name":"SyncGatewaySession"}


```

$ curl --cookie "SyncGatewaySession=971106d126515e4e071ad05070ffc76627289c16" -X GET http://localhost:4984/db/doc1

```


Response: {"_id":"doc1","_rev":"1-cd809becc169215072fd567eebd8b8de","foo":"bar"}


You can check that a valid session document exists in the DB, for your example the doc name will be:


_sync:session:2823i1826e9e2ad72af0409e0703f9bf1s9317d3


Check the expiration property to make sure the cookie is still active.


Andy


atom992

unread,
Jun 27, 2015, 10:26:57 AM6/27/15
to mobile-c...@googlegroups.com
Thank you very much. I can get/modify docs by SyncGatewaySession now.
Reply all
Reply to author
Forward
0 new messages