Spring Security OAuth2经过负载均衡导致redirect_uri使用http而不是https报redirect_uri mismatch错误

解决办法:添加前置过滤器,强制将scheme配置为https,将serverPort配置为443

@Slf4j
public class MyPreFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
        MyRequestWrapper myRequestWrapper = new MyRequestWrapper(httpRequest);

        filterChain.doFilter(myRequestWrapper, servletResponse);
    }
}

@Slf4j
public class MyRequestWrapper extends HttpServletRequestWrapper {

    public MyRequestWrapper(HttpServletRequest request) {
        super(request);
    }

    @Override
    public String getScheme() {
        return "https";
    }

    @Override
    public int getServerPort() {
        return 443;
    }
}

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/04/01/spring-security-oauth2-due-to-load-balancing-uri-uses-http-instead-of-https-to-redirect-uri-mismatch-error/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Spring Security OAuth2经过负载均衡导致redirect_uri使用http而不是https报redirect_uri mismatch错误
解决办法:添加前置过滤器,强制将scheme配置为https,将serverPort配置为443 @Slf4j public class MyPreFilter implements Filter { @Override publ……
<<上一篇
下一篇>>
文章目录
关闭
目 录