【问题标题】:Keycloak invalid redirect uri with Couchbase Sync Gateway OpenID Connect NginxKeycloak 使用 Couchbase 同步网关 OpenID Connect Nginx 的无效重定向 uri
【发布时间】:2017-11-14 21:03:52
【问题描述】:

我无法在 Keycloak 服务器和 Couchbase 同步网关之间连接 OpenID Connect。我的设置如下:我有一个 nginx,它为 Keycloak 和 Sync Gateway 提供 SSL 终止和反向代理。所以我的keycloak认证地址是这样的:

https://auth.domain.com

我的同步网关存储桶位于:

https://sg.domain.com/sync_gateway

我已经在 keycloak 中设置了一个带有授权码的机密客户端,它的重定向 url 是:

https://sg.domain.com/sync_gateway/_oidc_callback

我在 Couchbase Lite for .NET 中使用内置的 OpenIDConnectAuthenticator。当我的应用程序将用户带到 Keycloak 登录页面时,我得到:

Invalid parameter: redirect_uri

传递给我的应用的登录网址是:

https://auth.domain.com/auth/realms/realm/protocol/openid-connect/auth?access_type=offline&client_id=couchbase-sync-gateway&prompt=consent&redirect_uri=http%3A%2F%2Fsg.domain.com%2Fsync_gateway%2F_oidc_callback&response_type=code&scope=openid+email&state=

在其中我可以看到redirect_uri 是http。应该是 https。

我的同步网关配置是:

{
  "log": ["*"],
  "databases": {
    "sync_gateway": {
      "server": "http://cbserver:8091",
      "bucket": "sync_gateway",
      "users": { "GUEST": { "disabled": true, "admin_channels": ["*"] } },
      "oidc": {
        "providers": {
          "keycloakauthcode": {
            "issuer":"https://auth.domain.com/auth/realms/realm",
            "client_id":"couchbase-sync-gateway",
            "validation_key":"myclientid",
            "register":true
          }
        }
      }
    }
  }
}

我的 nginx 配置是:

events {
    worker_connections 768;
    multi_accept on;
}
http {
    proxy_buffer_size 128k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
    large_client_header_buffers  4 32k;        

    upstream auth_backend { 
        server server1:port1;
    }
    upstream cb_sync_gateway { 
        server server2:port2;
    }
    server { # AUTH 

        listen 443 ssl;
        server_name auth.domain.com;

        ssl on;
        ssl_certificate /local/ssl/domain_com.crt;
        ssl_certificate_key /local/ssl/domain_com.key;

        add_header Content-Security-Policy upgrade-insecure-requests;

        location / {
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;

            proxy_pass       http://auth_backend;
        }
    }

    server {
        listen 443 ssl;
        server_name sg.domain.com;

        ssl on;
        ssl_certificate /local/ssl/domain_com.crt;
        ssl_certificate_key /local/ssl/domain_com.key;

        add_header Content-Security-Policy upgrade-insecure-requests;

        location / {
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;

            proxy_pass       http://cb_sync_gateway;
        }
    }
}

Keycloak Standalone-ha.xml 具有代理设置:https://github.com/ak1394/keycloak-dockerfiles

我不确定这是否与 nginx 设置或 keycloak 设置有关。

有什么想法吗?

【问题讨论】:

    标签: nginx reverse-proxy openid-connect keycloak couchbase-sync-gateway


    【解决方案1】:

    我能够解决这个问题;可能不是最好的方式,但它现在正在工作。我还需要在 nginx 配置中进行设置:

    proxy_redirect http:// https://
    

    在 Keycloak 中,输入以下有效的重定向 url:

    http://sg.domain.com/sync_gateway/_oidc_callback
    

    如果有人在没有不安全的有效重定向的情况下找到一种方法来做到这一点,我会非常想知道,因为我知道不推荐这样做。

    编辑:

    我已在Couchbase Forums 中发帖,看来这可能是 Couchbase Mobile(Coucbase Lite 或 Sync Gateway)中的错误。他们在 Couchbase Lite for .NET 中提交了ticket

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 2022-12-10
      • 2017-02-09
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多