简体   繁体   中英

Spring Social Google return after login wrong

I have implemented Spring social for Facebook, Twitter and Google. For the first 2 it works but Google redirect the user to /signin after accepting on the google page where you allow my application access to your google+ account. /signin is a 404. If I make a page for /signin the page is shown but the user is not logged in.

I am to familiar with the underlying mechanics of connectController and GoogleConnectionFactory but i believe it should redirect the request back to where it came from and with access tokens. This is /auth/google i believe. I tried a redirect from /signin to /auth/google but that did not work. As mentioned for Twitter and Facebook there was no problem.

The code: public class SocialConfig implements SocialConfigurer

@Override
public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
    cfConfig.addConnectionFactory(new FacebookConnectionFactory(
            env.getProperty("facebook.app.id"),
            env.getProperty("facebook.app.secret")
    ));
    cfConfig.addConnectionFactory(new TwitterConnectionFactory(
            env.getProperty("twitter.consumer.key"),
            env.getProperty("twitter.consumer.secret")
    ));
    cfConfig.addConnectionFactory(new GoogleConnectionFactory(
            env.getProperty("google.app.id"),
            env.getProperty("google.app.secret")));
}

@Bean
public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) {
    return new ConnectController(connectionFactoryLocator, connectionRepository);
}

SecurityConfig.java

.apply(getSpringSocialConfigurer()); //to http.

private SpringSocialConfigurer getSpringSocialConfigurer() {
    SpringSocialConfigurer config = new SpringSocialConfigurer();
    config.alwaysUsePostLoginUrl(true);
    config.postLoginUrl("/");

    return config;
}

the jsp.

  //facebook
                <a href="${pageContext.request.contextPath}/auth/facebook" class="hidden-xs">
                    <img src="<c:url value="/static/img/fb-login.png"/>" height="32"/>      
                </a>

//twitter
                <a href="${pageContext.request.contextPath}/auth/twitter" class="hidden-xs">
                    <img src="<c:url value="/static/img/twitter-login.png"/>" height="20" width="24"/>      
                </a>
 //google
            <form name="go_signin" id="go_signin" action="<c:url value="/auth/google"/>" method="POST" class="float-left">          
                <div onclick="this.parentNode.submit();">
                    <img src="<c:url value="/static/img/google-login.png"/>" height="32"/>      
                </div>
                <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
                <input type="hidden" name="scope" value="https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.login" /> 
            </form>

In the google app console i set Redirect URIs to : {my_url}/auth/google and Javascript Origins just to my url. I tried almost every combination. anything but /auth/google will result in a redirect uri mismatch error before you get to the google login page

Any idea`s are welcome, thank you in advance.

这个项目有一个关于使用 spring-social-google 的很好的工作示例: https : //github.com/GabiAxel/spring-social-google-example

I had similar problem, after logging in, there was redirection to /signin, yet it was not performed by google, but by Spring Social Google plugin. It sends GET request to https://www.googleapis.com/plus/v1/people/me , which can only be called if Google+ Api is enabled for your application in Google Console.

redirect_uri should be /auth/google

This issue was discussed in https://github.com/GabiAxel/spring-social-google/issues/22 . In future release it will be fixed.

将 pom.xml 中 spring-social-google 的版本更新为 1.0.0.RC1 解决了我的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM