Spring nginx 的安全性 google oauth2 在 Nginx 上不工作
Spring security with nginx google oauth2 not working on Nginx
我创建了一个 google oauth2 登录应用程序。这在我的本地机器上完美运行。前端是react,后端是java。这是配置文件
spring:
security:
oauth2:
client:
registration:
google:
client-id:asdfdsaf
client-secret: asdfsadf
redirect-uri: http://localhost:8080/controller/oauth2/callback/google
scope:
- email
- profile
这是java代码
`httpSecurity.cors().and().csrf().disable().authorizeRequests().antMatchers("**/api/**")
.authenticated().and().oauth2Login().authorizationEndpoint().baseUri("/oauth2/authorize")
.authorizationRequestRepository(cookieAuthorizationRequestRepository()).and()
.userInfoEndpoint().oidcUserService(oidcUserService).and().redirectionEndpoint()
.baseUri("/oauth2/callback/*").and().userInfoEndpoint().userService(customOAuth2UserService)
.and().successHandler(oAuth2AuthenticationSuccessHandler)
.failureHandler(oAuth2AuthenticationFailureHandler);`
这里是错误
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Jul 15 02:06:05 UTC 2020
There was an unexpected error (type=Not Found, status=404).
No message available
这是我的 nginx 配置
# configure load-balancing
upstream backend {
server localhost:8080;
server localhost:8081;
keepalive 64;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name domain.app www.domain.app xxx.xx.xxx.xxx;
location / {
try_files $uri /index.html;
root /var/www/build;
index index.html index.htm;
}
location /controller {
proxy_pass http://backend;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header Host $http_host;
}
}
由于 nginx 的工作方式。重定向不会像在本地一样工作。我尝试了很多解决方案。最后我用react-google-login来完成任务。
我创建了一个 google oauth2 登录应用程序。这在我的本地机器上完美运行。前端是react,后端是java。这是配置文件
spring:
security:
oauth2:
client:
registration:
google:
client-id:asdfdsaf
client-secret: asdfsadf
redirect-uri: http://localhost:8080/controller/oauth2/callback/google
scope:
- email
- profile
这是java代码
`httpSecurity.cors().and().csrf().disable().authorizeRequests().antMatchers("**/api/**")
.authenticated().and().oauth2Login().authorizationEndpoint().baseUri("/oauth2/authorize")
.authorizationRequestRepository(cookieAuthorizationRequestRepository()).and()
.userInfoEndpoint().oidcUserService(oidcUserService).and().redirectionEndpoint()
.baseUri("/oauth2/callback/*").and().userInfoEndpoint().userService(customOAuth2UserService)
.and().successHandler(oAuth2AuthenticationSuccessHandler)
.failureHandler(oAuth2AuthenticationFailureHandler);`
这里是错误
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Jul 15 02:06:05 UTC 2020
There was an unexpected error (type=Not Found, status=404).
No message available
这是我的 nginx 配置
# configure load-balancing
upstream backend {
server localhost:8080;
server localhost:8081;
keepalive 64;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name domain.app www.domain.app xxx.xx.xxx.xxx;
location / {
try_files $uri /index.html;
root /var/www/build;
index index.html index.htm;
}
location /controller {
proxy_pass http://backend;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header Host $http_host;
}
}
由于 nginx 的工作方式。重定向不会像在本地一样工作。我尝试了很多解决方案。最后我用react-google-login来完成任务。