1

我無法連接Keycloak服務器和Couchbase同步網關之間的OpenID連接。我的設置如下:我有一個nginx爲Keycloak和Sync Gateway提供SSL終止和反向代理。所以我keycloak認證地址是這樣的:Keycloak無效重定向uri與Couchbase同步網關OpenID連接Nginx

https://auth.domain.com 

我的SYNC網關桶是:

https://sg.domain.com/sync_gateway 

我已經建立了機密的客戶與授權碼和重定向URL keycloak它是:

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。

我SYNC網關的配置是:

{ 
    "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獨立-ha.xml具有代理設置按:https://github.com/ak1394/keycloak-dockerfiles

我不是確定這是否與nginx設置或keycloak設置有關。

任何想法?

回答

1

我能夠解決這個問題;可能不是最好的方式,但它現在工作。我需要在nginx的配置也成立:

proxy_redirect http:// https:// 

和Keycloak,把下面的有效導向網址:

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

如果有人發現了一個辦法做到這一點,而無需不安全有效的重定向我會非常熱衷於知道,因爲我知道這不被推薦。

編輯:

我已經張貼在Couchbase Forums,它似乎是它可以在Couchbase移動(Coucbase精簡版或SYNC網關)的錯誤。他們已經在Couchbase Lite for .NET中提交了ticket