栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用http而不是https的redirect_uri

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用http而不是https的redirect_uri

我遇到了与Google完全相同的问题。

具有以下微服务架构

Google Auth Server  Zuul Gateway (:8080)     /       /        /       Other      OAuth2Client (:5000)

在本地计算机上运行时,一切正常,但是在AWS Elastic Beanstalk中,我捕获了相同的异常。

调试之后,我发现在我的情况下,当OAuth2Client位于Zuul代理(它们在单独的微服务中实现)后面时,我实际上在内部检查中获得了不同的redirect_uri值

OAuth2LoginAuthenticationProvider

if (!authorizationResponse.getRedirectUri().equals(authorizationRequest.getRedirectUri())) {    OAuth2Error oauth2Error = new OAuth2Error(INVALID_REDIRECT_URI_PARAMETER_ERROR_CODE);    throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString());}

因此,对于AWS,我具有以下值:

authorizationResponse.getRedirectUri()http://[INNER_AWS_ESB_IP]:5000/auth/login/oauth2/pre/googleauthorizationRequest.getRedirectUri()https://[MY_PROJECT_DOMAIN_NAME]/auth/login/oauth2/pre/google

其中

[INNER_AWS_ESB_IP]
,AWS Elastic
Beanstalk中的内部网络的IP地址
[MY_PROJECT_DOMAIN_NAME]
是我的项目的域名,该域名被硬编码
application.yml
redirect-uri-template
参数。

我有以下配置

application.yml
我的 OAuth2Client 的microService

server:  port: 5000  servlet:     contextPath: /auth  use-forward-headers: truespring:  security:    oauth2:      resource:        filter-order: 3      client:        registration:          google: client-id:  [REMOVED] client-secret: [REMOVED] redirect-uri-template: ${MY_PROJECT_DOMAIN_NAME:http://localhost:8080}/auth/login/oauth2/pre/google scope: profile,email

洛雷诺,您拥有哪种建筑?您可以共享您的配置吗?

更新

似乎该问题与版本科学5.0中的Spring Security Oauth2 Client的实现直接相关

如果在某些单独的虚拟机上启动Zuul Gateway微服务而在本地计算机上启动其他微服务,则问题可以重现☝️因此,应从VM上的浏览器调用Google。

*帮助我避免此问题 *的解决方案 是添加

Filter
具有
HttpServletRequestWrapper
可覆盖方法的custom
的custom 并返回“正确的” URL以满足签入中的
OAuth2LoginAuthenticationProvider.java:115
要求。

  1. application.yml
    Oauth2客户端中

myCloudPath: ${MY_PROJECT_DOMAIN_NAME:http://localhost:8080}

  1. 在里面
    SecurityConfig
@Value("${myCloudPath}")private String myCloudPath;@Overridepublic void configure(HttpSecurity http) throws Exception {http.     addFilterBefore(new MyCustomFilter(myCloudPath), OAuth2LoginAuthenticationFilter.class).     ...
  1. 过滤

    public class MyCustomFilter implements Filter {private static final Logger logger = LogManager.getLogger(MyCustomFilter.class);private String myCloudPath;public MyCustomFilter(String myCloudPath) {    this.myCloudPath= myCloudPath;}@Overridepublic void init(FilterConfig filterConfiguration) throws ServletException {    logger.info("MyCustomFilter init");}public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)        throws IOException, ServletException {    request = new MyHttpServletRequestWrapper((HttpServletRequest) request, myCloudPath);    chain.doFilter(request, response);}@Overridepublic void destroy() {    logger.info("MyCustomFilter destroy");}

    }

  2. HttpServletRequestWrapper

    public class MyHttpServletRequestWrapper extends HttpServletRequestWrapper {public final String redirectUrl;public MyHttpServletRequestWrapper(HttpServletRequest request, String myCloudPath) {    super(request);    this.redirectUrl = myCloudPath + request.getRequestURI();}@Overridepublic StringBuffer getRequestURL() {    return new StringBuffer(redirectUrl);}

    }



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/670631.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号