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.
/signininstead of/singup. - Jagger