spring-social-google
spring-social-google copied to clipboard
When using with ConnectController, scope is not sent to the Google server
When using with ConnectController, the scope value is not sent to the Google server (Missing required parameter: scope). At the same time everything is fine with authentication. I use authentication with org.springframework.social.security.SocialAuthenticationFilter.
Property "scope" has to be added to the GoogleConnectionFactory. The values for the "scope" parameters are specified here: https://developers.google.com/accounts/docs/OAuth2Login#scope-param
XML config: <bean class="org.springframework.social.google.connect.GoogleConnectionFactory"> <constructor-arg value="${google.clientId}" /> <constructor-arg value="${google.clientSecret}" /> <property name="scope" value="profile" /> </bean>
Java Config: GoogleConnectionFactory gcf = new GoogleConnectionFactory(env.getProperty("google.clientId"), env.getProperty("google.clientSecret")); gcf.setScope("profile"); connectionFactoryConfigurer.addConnectionFactory(gcf);
what workaround for this problem?
@MikhailErofeev Did you find any workaround to this problem?
@raoravik nope, switch to twitter :)
Well, I did manage to write a custom class and ensure the scope is sent. However, the flow is still not correct. After logging through Google account, it takes me to the register page where Name fields are populated but I still need to enter the email and password. :( Trying to figure out the issue..
Here is the code:
import org.springframework.social.google.connect.GoogleConnectionFactory;
public class CustomGoogleConnectionFactory extends GoogleConnectionFactory {
private String scope = "profile";
public CustomGoogleConnectionFactory(String clientId, String clientSecret) {
super(clientId, clientSecret);
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}
And in your SocialContext.java
CustomGoogleConnectionFactory googleConnectionFactory = new CustomGoogleConnectionFactory(
env.getProperty("google.consumerKey"),
env.getProperty("google.consumerSecret"));
googleConnectionFactory.setScope("profile");
cfConfig.addConnectionFactory(googleConnectionFactory);
Are you sure you have a "scope" field in your page and that it is submitted correctly to the server? Can attach the login page source, or even better the entire application (or just the login part)?
Was there any resolution or workaround to this issue? The code same above for CustomGoogleConnectionFactory does not resolve the issue.
Specifying the scope directly in the login page worked for me:
<form action="<c:url value="/auth/google" />" method="POST">
<input type="hidden" name="scope" value="profile" />
<button type="submit" class="btn btn-lg btn-google"><i class="fa fa-google-plus"></i> | Sign Up with Google</button></a><br />
</form>
Using an interceptor works just fine.
public class GoogleScopeInterceptor implements ConnectInterceptor<Google> {
@Override
public void preConnect(ConnectionFactory<Google> connectionFactory, MultiValueMap<String, String> parameters, WebRequest request) {
parameters.add("scope", "profile");
}
@Override
public void postConnect(Connection<Google> connection, WebRequest request) {
return;
}
}
and in the config:
@Bean
public ConnectController connectController(
ConnectionFactoryLocator connectionFactoryLocator,
ConnectionRepository connectionRepository) {
ConnectController cc = new ConnectController(connectionFactoryLocator, connectionRepository);
cc.addInterceptor(new GoogleScopeInterceptor());
return cc;
}
With the following dependencies worked fine for me:
<spring.social.version>1.1.6.RELEASE</spring.social.version>