CouchDB与Auth0

时间:2016-09-05 13:31:19

标签: couchdb ionic2 auth0

是否可以将Auth0与CouchDB或Cloudant一起使用?如果是这样,有没有人知道教程,代码示例或github项目的例子?

这个问题已在Auth0-Forum(不是我)中提出,但没有回复:https://auth0.com/forum/t/can-you-use-auth0-with-couchdb-or-cloudant/3127

在我的特殊情况下,我想将一个带有Auth0的Ionic 2应用程序连接到没有中间(API)层的CouchDB实例。

任何帮助将不胜感激!

4 个答案:

答案 0 :(得分:4)

couch_jwt_auth插件允许用户通过JWT令牌进行身份验证,从而允许这种情况。关于如何将它与pouchdb和Auth0一起使用,甚至还有example project,所以猜测这对你有用。

我使用相同的插件对用户进行身份验证,并且运行正常。我实际上维护了fork它允许使用非对称密钥进行JWT签名验证(RS256) - 是的,一旦我有足够的信心就会有拉取请求。

答案 1 :(得分:1)

用户是否在couchdb中拥有自己的数据库? 如果没有服务器端中间件,您将无法仅限制对用户数据的访问。 如果是这种情况,你可以考虑使用oauth。

我对Auth0并不深入,但似乎支持它https://auth0.com/docs/oauth2-examples 作为CouchDB http://docs.couchdb.org/en/stable/api/server/authn.html#oauth-authentication

答案 2 :(得分:0)

试试这个:https://github.com/softapalvelin/couch_jwt_auth此插件允许用户通过JWT令牌进行身份验证。

答案 3 :(得分:0)

CouchDB 3.1开箱即用地支持JWT身份验证。

Couch docs on JWT auth are here

基本上,更新配置的[chttpd]部分以包括下面的JWT部分。好了,您可以删除默认和/或cookie,但是保留它们非常有用:

[chttpd]
authentication_handlers = {chttpd_auth, cookie_authentication_handler}, {chttpd_auth, jwt_authentication_handler}, {chttpd_auth, default_authentication_handler}

然后添加此部分,在文档中没有示例地提及该部分:

[jwt_auth]
; List of claims to validate
; As of couch 3.1, can NOT require issuer:
; required_claims = {iss, "http://issuer"} <-- does not work
; I left it blank and it's fine
required_claims =

,然后添加或取消注释此部分:

[jwt_keys]
; Configure at least one key here if using the JWT auth handler.
; I found I had to inclue the 'kid' claim, even if it is just "_default".
; REMINDER: BASE64 ENCODED!
hmac:_default = aGVsbG8=
hmac:demo = aGVsbG8=

这是base64编码的“ hello”。

要为此获得JWT,请执行以下操作:

// once off...
const secret = 'hello'

// then, in an express-jwt handler somewhere...
const token = sign(data, secret, { subject: user.name, audience, algorithm, keyid: 'demo' });
return res.send({ error: null, token })

我发现主题(sub),受众(aud),算法(alg)和Keyid(kid)必须作为JWT声明包括在内,或者CouchDB不接受身份验证。