2016-03-18 46 views
0

我正在使用cookie身份验证实现自定义身份验证。所以,我在玩同步网关REST API来创建用户和会话。我可以成功创建用户,但无法通过/ _session API创建会话。 以下是我遵循的步骤。无法通过CouchBase同步网关创建会话管理REST API

1.创建用户

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

2.让用户

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

Respone :["chef123"] 

3.创建会话

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}} 

任何人都可以请解释API为什么给出以下响应。

{ “authentication_handlers”: “默认”, “曲奇”], “OK”:真实的, “userCtx”:{ “通道”:{}, “名”:空}}

+0

是你的问题解决了。我有同样的问题。该问题的 – krishnan

+1

在请求URL的末尾是“/”。我尝试使用http:// localhost:4985/db/_session而不是http:// localhost:4985/db/_session //并且它工作正常 – krishnan

回答

0

authentication_handlers是您用来创建会话的方法(也可以是内置的脸谱或角色登录功能)。 userCtx有该用户的数据等存取有用的信息:

  • channels:用户正在通过同步功能给予
  • admin_channels存取的信道:用户在配置文件中给定的访问的信道
  • roles:该用户

的角色看到会话文档的详细信息:http://developer.couchbase.com/documentation/mobile/1.2/develop/references/sync-gateway/admin-rest-api/session-admin/get-db-session-sessionid/index.html

设置身份验证与SYNC网关,您可以检查这些博客: