0

在我的Spring Boot应用程序中,我使用Spring Social(1.1.4.RELEASE)(Facebook,Google,LinkedIn和Twitter)实现了登录。Spring社交:当服务器后面的代理服务器重定向url

在登录过程中,服务器调用以下HTTP GET:

https://accounts.google.com/o/oauth2/auth?client_id=XXX&response_type=code&redirect_uri=http://xzy.com:91/auth/google&scope=email&state=YYY 

问题是在这里:REDIRECT_URI = HTTP://xzy.com:91/AUTH /谷歌

该应用程序在代理之后,我需要变化REDIRECT_URI

http://xzy.com:91/auth/google - >http://xzy.com/auth/google

我想这是很常见的问题,但我没能找到工作液(

我POM:

<dependency> 
     <groupId>org.springframework.social</groupId> 
     <artifactId>spring-social-security</artifactId> 
     <version>${spring-social-version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.social</groupId> 
     <artifactId>spring-social-linkedin</artifactId> 
     <version>${spring-social-linkedin.version}</version> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework.social</groupId> 
     <artifactId>spring-social-twitter</artifactId> 
     <version>${spring-social-twitter.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.social</groupId> 
     <artifactId>spring-social-google</artifactId> 
     <version>${spring-social-google.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.social</groupId> 
     <artifactId>spring-social-facebook</artifactId> 
     <version>${spring-social-facebook.version}</version> 
    </dependency> 

回答

1
@Bean 
public ProviderSignInController providerSignInController(ConnectionFactoryLocator connectionFactoryLocator, UsersConnectionRepository usersConnectionRepository) { 
    ProviderSignInController controller = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, new SimpleSignInAdapter()); 
    // get the url from config, this just for example 
    controller.setApplicationUrl("http://xzy.com"); 
    return controller; 
} 

正如你可以从代码spring-social阅读,application url将替换基本网址。

protected String callbackUrl(NativeWebRequest request) { 
     if (callbackUrl != null) { 
      return callbackUrl; 
     } 
     HttpServletRequest nativeRequest = request.getNativeRequest(HttpServletRequest.class); 
     if (applicationUrl != null) { 
      return applicationUrl + connectPath(nativeRequest); 
     } else { 
      return nativeRequest.getRequestURL().toString(); 
     } 
    } 
+0

感谢您的建议,但它仍然无法正常工作。它似乎可以用于HTTP GET xxx/signup/facebook,但我的请求是xxx/auth/facebook –

+1

请发布你的配置 – chaoluo

相关问题