couchbase 同步网关中多个数据库的身份验证

Authentication for multiple databases in couchbase sync gateway

如何使用 Couchbase 同步网关同时对多个数据库进行身份验证?

我正在开发一个移动应用程序,我在其中使用通过 couchbase 同步网关与 couchbase 服务器同步的 pouchdb。我必须要同步的数据库:"messages" 和 "profiles".

Sync 工作得很好,但我有一个问题:我只能同时对一个数据库进行身份验证,但不能同时对两个数据库进行身份验证:我正在使用 here 所述的自定义身份验证,即通过调用“/database1/_session”端点实现。然后 returns 一个让我登录数据库 1 的 cookie。如果我现在也想同步第二个数据库,我会调用“/database2/_session”来覆盖第一个 cookie,即我是现在可以同步第二个数据库,但不能再同步第一个了。

有没有办法为多个数据库启用身份验证?有没有办法创建全局用户,即仅对一个数据库无效的用户?或者有其他方法可以解决这个问题吗?

提前致谢!

好的,经过几个小时尝试编写操纵 cookie 等的代理之后。我找到了一个更简单的解决方案:

在我的服务器应用程序中,我可以为所有数据库的用户设置一个令牌作为密码,我可以在登录时将其发送到应用程序。然后应用程序可以只使用 http 基本身份验证:

  this.db.sync(this.cfg.couchbase + 'messages', {
    live: true,
    retry: true,
    ajax: {
      headers: {
          'Authorization': 'Basic ' + btoa(this.userID + ':' + token)
      }
    }
  }).on('change', this.changed.bind(this))
    .on('error', err => console.error(err));
});