【问题标题】:Why is the CouchDB JWT Authentication with Auth0 not working for me?为什么使用 Auth0 的 CouchDB JWT 身份验证对我不起作用?
【发布时间】:2021-04-01 18:29:33
【问题描述】:

我一直在尝试将 CouchDB 中的 JWT 身份验证方法与 Auth0 一起使用。按照 https://docs.couchdb.org/en/stable/api/server/authn.html#jwt-authentication 的文档,我在我的 default.ini 文件中添加了 authentication_handlers 并像这样配置了 jwt_auth 和 jwt_keys:

[jwt_auth]
; List of claims to validate
required_claims = alg,kid,sub

[jwt_keys]
rsa:<kid> = -----BEGIN PUBLIC KEY-----\n
<PublicKey>
\n-----END PUBLIC KEY-----\n

我从 Auth0 (https://[myDomain]/.well-known/jwks.json) 获得了孩子和公钥。现在,当我请求 JWT 令牌并将其添加到针对 _session 端点的 CouchDB 请求时,我得到以下响应:

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

我觉得我在 default.ini 文件中做错了什么。谁能帮帮我?

【问题讨论】:

    标签: jwt couchdb auth0


    【解决方案1】:

    您似乎没有在 CouchDB 中启用 JWT 身份验证。我这样说是因为:

        "info": {
            "authentication_handlers": [
                "cookie",
                "default"
            ]
        }
    

    还应包括"jwt"

    为此,CouchDB 配置中的 [chttpd] 块应包括:

    {chttpd_auth, jwt_authentication_handler}
    

    此外,我认为您不需要列出这三个必需的声明。前几天我才开始工作,因为 Couch 需要这些,所以你不需要列出它们。事实上,当我列出其中任何一个时,我都会收到关于“重复要求”之类的错误。

    另外,请确保 JWT 中没有 iss(颁发者)声明。这个问题可能会在未来的版本中得到解决,但在撰写本文时,为了让它与 Couch 3.1 一起使用,我必须明确确保没有 iss 声明。

    更多详情in this issue.

    【讨论】:

      【解决方案2】:

      所以这很尴尬,但我的问题是我没有输入 PEM 格式的公钥,所以我所要做的就是使用这个命令:

      curl https://[myDomain]/pem -s | openssl x509 -pubkey -noout

      获取 PEM 格式并使用它来配置 CouchDB。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-19
        • 2018-12-06
        • 2014-01-28
        • 2019-06-06
        • 2020-01-25
        • 2021-03-07
        • 2021-03-17
        • 1970-01-01
        相关资源
        最近更新 更多