spring-social-google icon indicating copy to clipboard operation
spring-social-google copied to clipboard

When using with ConnectController, scope is not sent to the Google server

Open sergey-suloev opened this issue 10 years ago • 11 comments

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.

sergey-suloev avatar Dec 29 '13 06:12 sergey-suloev

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);

vedab avatar Mar 27 '14 15:03 vedab

what workaround for this problem?

MikhailErofeev avatar Apr 12 '14 04:04 MikhailErofeev

@MikhailErofeev Did you find any workaround to this problem?

raoravik avatar Apr 28 '14 05:04 raoravik

@raoravik nope, switch to twitter :)

MikhailErofeev avatar Apr 28 '14 07:04 MikhailErofeev

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..

raoravik avatar May 21 '14 05:05 raoravik

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);

raoravik avatar May 21 '14 05:05 raoravik

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)?

GabiAxel avatar May 21 '14 09:05 GabiAxel

Was there any resolution or workaround to this issue? The code same above for CustomGoogleConnectionFactory does not resolve the issue.

jharrisweinberg avatar Jul 13 '14 20:07 jharrisweinberg

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>

Tketa avatar Aug 04 '14 10:08 Tketa

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;
	}

vauvenal5 avatar Apr 05 '17 10:04 vauvenal5

With the following dependencies worked fine for me:

<spring.social.version>1.1.6.RELEASE</spring.social.version> <groupId>org.springframework.social</groupId> <artifactId>spring-social-google</artifactId> 1.0.0.RELEASE <groupId>org.springframework.social</groupId> <artifactId>spring-social-core</artifactId> ${spring.social.version} <groupId>org.springframework.social</groupId> <artifactId>spring-social-config</artifactId> ${spring.social.version} <groupId>org.springframework.social</groupId> <artifactId>spring-social-web</artifactId> ${spring.social.version} <groupId>org.springframework.social</groupId> <artifactId>spring-social-security</artifactId> ${spring.social.version}

SteChronis avatar Dec 05 '18 10:12 SteChronis