Keycloak / Spring启动无法将代码转换为令牌

时间:2019-05-15 09:47:53

标签: spring-boot nginx keycloak

我在centos 7服务器上安装了keycloak,并在同一台服务器上部署了spring boot项目。

问题在于登录后,我得到了

[nio-8090-exec-2] o.k.adapters.OAuthRequestAuthenticator: failed to turn code into token
May 20 16:17:08 java[858]: java.net.ConnectException: Connection timed out (Connection timed out)
 java[858]: at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_212]
 java[858]: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_212]
 java[858]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_212]
 java[858]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_212]
 java[858]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_212]
 java[858]: at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_212]
 java[858]: at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:543) ~[httpclient-4.5.8.jar!/:4.5.8]
+ 52 more

我的密钥斗篷配置:

a busy cat

application.properties

server.port = 8090
server.servlet.contextPath=/demo
keycloak.auth-server-url=http://mywebsite.com/auth
keycloak.realm=myREALM
keycloak.resource=login
keycloak.credentials.secret=xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx
keycloak.security-constraints[0].authRoles[0]=user
keycloak.security-constraints[0].securityCollections[0].patterns[0]=/test/*

nginx.conf

upstream keycloak {
    ip_hash;
    server 127.0.0.1:8080;
}

upstream demoServer {
    ip_hash;
    server 127.0.0.1:8090;
}

server {
    listen 80;
    listen [::]:80;
    #server_name mywebsite.com;
    #return 301 https://$host$request_uri;
} 

server {
    listen 443 ssl http2;
    ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem; # managed by Certbot
    ssl_session_cache shared:SSL:1m;
    ssl_prefer_server_ciphers on;

    server_name mywebsite.com;

    location /auth/ { 
      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 $scheme; 
      proxy_pass http://keycloak/auth/;

    } 

    location /demo/ { 
      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 $scheme;
      proxy_pass http://demoServer/demo/;
    }
}

结果

a busy cat

PS:我正在使用Keycloak 6.0.0和Spring Boot 2.1.4

0 个答案:

没有答案