错误 org.keycloak.adapters.OAuthRequestAuthenticator - 无法将代码转换为令牌

ERROR org.keycloak.adapters.OAuthRequestAuthenticator - failed to turn code into token

我们的应用程序、Nginx 和 keycloak 有问题。有3个实例:实例1 APP,实例2 NGINX(反向代理)和实例3 Keycloak。

当用户登录时,他在 keycloak 中创建会话,但是当他 return 进入 SiAe 应用程序时,他 return 进入 403。 我们进入keycloak管理控制台,看到session成功打开了。但是应用程序的 return 不可能起作用。

日志

Nginx:

    "GET /opensat/?state=dcc1c40f-3183-4c7b-8342-f7df620cf0b3&session_state=605ba79a-ee05-4918-a96d-71466e31210a&code=fe066a17-a97a-495c-94f9-b1e5e3d6ac1f.605ba79a-ee05-4918-a96d-71466e31210a.f91920a4-3267-4de5-9788-24093a32c217 HTTP/1.1" **403 405** "https://mydomain/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0"

应用程序:

ERROR org.keycloak.adapters.OAuthRequestAuthenticator  - failed to turn code into token
java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:196)
        at java.net.SocketInputStream.read(SocketInputStream.java:122)
        at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
        at sun.security.ssl.InputRecord.read(InputRecord.java:480)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
        at org.apache.http.conn.ssl.SSLSocketFactory.createLayeredSocket(SSLSocketFactory.java:573)
        at org.keycloak.adapters.SniSSLSocketFactory.createLayeredSocket(SniSSLSocketFactory.java:114)
        at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:557)
        at org.keycloak.adapters.SniSSLSocketFactory.connectSocket(SniSSLSocketFactory.java:109)
        at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)
        at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)

钥匙斗篷:

**INFO** [org.keycloak.storage.ldap.LDAPIdentityStoreRegistry] (default task-1) Creating new LDAP Store for the LDAP storage provider: 'ldap_pre', LDAP Configuration: {pagination=[true], fullSyncPeriod=[-1], usersDn=[ou=usuarios,dc=domain,dc=es], connectionPooling=[true], cachePolicy=[DEFAULT], useKerberosForPasswordAuthentication=[false], importEnabled=[true], enabled=[true], changedSyncPeriod=[86400], bindDn=[cn=admin,dc=domain,dc=es], usernameLDAPAttribute=[uid], lastSync=[1575269470], vendor=[other], uuidLDAPAttribute=[entryUUID], connectionUrl=[ldap://MIIP:389], allowKerberosAuthentication=[false], syncRegistrations=[false], authType=[simple], debug=[false], searchScope=[1], useTruststoreSpi=[ldapsOnly], priority=[0], userObjectClasses=[inetOrgPerson, organizationalPerson, person], rdnLDAPAttribute=[cn], editMode=[WRITABLE], validatePasswordPolicy=[false], batchSizeForSync=[1000]}, binaryAttributes: []

配置:

Nginx:

location / {

        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Server $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-Host   $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://IP_KEYCLOAK:8081;
}

钥匙斗篷:

     ....
        <server name="default-server">
                <http-listener name="default" socket-binding="http" redirect-socket="proxyhttps" proxy-address-forwarding="true" enable-http2="true"/>
     ......
             <socket-binding name="proxy-https" port="443"/>
     .....

APP.json:

{
  "realm": "domain",
  "auth-server-url": "https://domainkeycloak/",
  "ssl-required": "none",
  "resource": "sso",
  "enable-cors" : true,
  "credentials": {
    "secret": "98236f9a-c8b1-488c-8b36-ace4f95b1aa6"
  },
  "confidential-port": 0,
  "disable-trust-manager":true,
  "allow-any-hostname" : true
}

有人可以帮助我们吗?

错误Connection reset表示应用程序无法向Keycloak服务器发出请求。由于您将 auth-server-url 设置为 https://domainkeycloak/

,因此您应该通过使用 443 端口登录到应用程序服务器和 telnet keycloak 域来进一步调查该问题

解决方案已经将keycloak与其他Nginx分开,而不是将一个Nginx用于APP和Keycloak。现在,我们的 APP 有 2 个 Nginx 和 运行 OK keycloak。