1

I am working on implementing custom authentication using cookie Auth. So, I was playing around the sync gateway REST API to create user and session. I could successfully create the user but unable to create session via /_session API. Following are the steps I followed.

1. Create user

POST /cookbook/_user/ HTTP/1.1
Host: localhost:4985
Content-Type: application/json
{
"name": "chef123",
"password": "1234"
}

2. Get Users

GET /cookbook/_user/ HTTP/1.1
Host: localhost:4985
Content-Type: application/json

Respone :["chef123"]

3. Create Session

  POST /cookbook/_session HTTP/1.1
    Host: localhost:59840
    Content-Type: application/json
    {
        "name": "chef123",
        "ttl": 1800
    }

Expected:
{
    "cookie_name": "SyncGatewaySession", 
    "expires": "2014-11-07T16:42:11.675519255-08:00", 
    "session_id": "c2425fa7d734bc8c3f6c507854166bef56a5fbc6"
}

Instead received:
{"authentication_handlers":["default","cookie"],"ok":true,"userCtx":{"channels":{},"name":null}} 

Can Anyone please explain why is the API giving the following response.

{"authentication_handlers":["default","cookie"],"ok":true,"userCtx":{"channels":{},"name":null}}

Dnavir
  • 556
  • 3
  • 11
  • is your problem solved. I am having the same issue. – krishnan Aug 11 '16 at 12:22
  • 2
    for the the problem was "/" at the end of the request URL. I tried http://localhost:4985/db/_session instead of http://localhost:4985/db/_session// and it worked – krishnan Aug 11 '16 at 12:43

2 Answers2

0

authentication_handlers is the method you used to create the session (it could be the built-in facebook or persona login features as well). userCtx has useful information on the data access for this user like:

  • channels: The channels the user was given access to via the Sync Function
  • admin_channels: The channels the user was given access to in the config file
  • roles: The roles of this user

See the session docs for details: http://developer.couchbase.com/documentation/mobile/1.2/develop/references/sync-gateway/admin-rest-api/session-admin/get-db-session-sessionid/index.html

To set up authentication with Sync Gateway you can check those blogs:

jamiltz
  • 1,144
  • 8
  • 15
0

As mentioned in the comments by krishnan, the solution to this problem is removing the trailing slash from the URI. I had the same issue.

So, instead of: POST /cookbook/_session/

Use: POST /cookbook/_session

JR Lawhorne
  • 3,192
  • 4
  • 31
  • 41