【问题标题】:Spring security with nginx google oauth2 not working on Nginxnginx google oauth2 的 Spring 安全性在 Nginx 上不起作用
【发布时间】:2020-11-04 11:17:29
【问题描述】:

我创建了一个 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;
  }
}

【问题讨论】:

  • 最后,我无法修复它。我使用了 react-google-login 并使其工作。

标签: spring-boot nginx spring-security google-oauth nginx-reverse-proxy


【解决方案1】:

因为 nginx 的工作方式。重定向不会像在本地一样工作。我尝试了很多解决方案。最后我使用 react-google-login 来完成任务。

【讨论】:

    猜你喜欢
    • 2014-07-25
    • 1970-01-01
    • 2021-06-24
    • 2016-09-10
    • 1970-01-01
    • 2015-06-20
    • 2011-07-03
    • 1970-01-01
    • 2020-11-07
    相关资源
    最近更新 更多