Spring Social:服务器支持

时间:2017-04-08 07:47:10

标签: spring spring-security spring-security-oauth2 spring-social

在我的Spring Boot应用程序中,我使用Spring Social(1.1.4.RELEASE)(Facebook,Google,LinkedIn和Twitter)实现了登录。

在登录过程中,服务器调用以下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 / google

代理后面的应用程序,我需要将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 个答案:

答案 0 :(得分:2)

@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();
        }
    }