【发布时间】:2021-04-28 08:57:54
【问题描述】:
我一直在互联网上寻找解决我的问题的方法,如下 -
我们有一个带有 Spring Security OAuth2 和 Azure Active Directory 集成的 Spring Boot 应用程序来管理我们的外部身份验证。当我们尝试登录时,登录URL中的redirect_uri是错误的。
redirect_uri 没有像 application.yaml 和 Azure AD 门户中定义的那样显示“&redirect_uri=https://10.10.10.10/v1/login/oauth2/code/”,而是显示为“&redirect_uri=http ://10.10.10.10:8080/v1/login/oauth2/code/”。如您所见,它正在删除 https 方案并添加端口,这会导致由于 redirect_uri 不匹配而导致登录错误。需要注意的是,这在本地可以正常工作,但是当部署到反向代理后面的环境时,它就不起作用了。
我的尝试 -
将以下属性添加到 application.yaml -
- server.forward-headers-strategy=NATIVE
- server.forward-headers-strategy=FRAMEWORK
- server.tomcat.internal-proxies=.*
- server.tomcat.remoteip.protocol-header=x-forwarded-proto
- server.tomcat.remoteip.remote-ip-header=x-forwarded-for
将此添加到路径的 nginx 配置中 -
resolver 127.0.0.11 valid=30s;
set $upstream_be application;
proxy_pass http://$upstream_be:8080;
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 $host;
不幸的是,这些都没有奏效,问题仍然存在。有什么想法吗?
相关 pom.xml 版本:spring-boot、spring-security=2.4.5、所有 azure-spring 依赖项=3.4.0
在我们将 azure 依赖项从 2.3.5 升级到 3.4.0 之前,这也运行良好。
【问题讨论】:
标签: spring spring-security azure-active-directory