问题
We are using spring-social to integrate our application to facebook. In OAuth2AuthenticationService, scope is empty. We set scope as a input on form.But it was not work and scope could not be set . We could not get user email.
Are there any way to override "OAuth2AuthenticationService" scope variable ?
Not: Spring social verison is 1.1.0.BUILD-SNAPSHOT
We used spring social sample which contains security xml version
<form name="fb_signin" id="fb_signin" action="../auth/facebook"
method="post">
<input type="hidden" name="scope"
value="email,publish_stream,read_stream,offline_access" />
<button type="submit"> <img src="../images/social/facebook/sign-in-with-facebook.png" /> </button>
<!--
<input
type="image"
src="../images/social/facebook/sign-in-with-facebook.png"
align="right" />
-->
</form>
回答1:
In your configuration, you need to specify scope
as a property of the FacebookAuthenticationService
. This is the service that handles calls to auth/facebook
In XML configuration, instead of:
<facebook:config app-id="${facebook.clientId}" app-secret="${facebook.clientSecret}"/>
use:
<bean id="connectionFactoryLocator" class="org.springframework.social.security.SocialAuthenticationServiceRegistry">
<property name="authenticationServices">
<list>
<bean class="org.springframework.social.facebook.security.FacebookAuthenticationService">
<constructor-arg value="${facebook.clientId}" />
<constructor-arg value="${facebook.clientSecret}" />
<property name="scope" value="email" />
</bean>
</list>
</property>
</bean>
This works with Spring Social 1.1.0.M3
回答2:
To use the above XML config with Spring Social 1.1.0.RELEASE, use the minor edited version:
<bean id="connectionFactoryLocator" class="org.springframework.social.security.SocialAuthenticationServiceRegistry">
<property name="authenticationServices">
<list>
<bean class="org.springframework.social.facebook.security.FacebookAuthenticationService">
<constructor-arg value="${facebook.app.id}" />
<constructor-arg value="${facebook.app.secret}" />
<!-- Important: The next property name changed from "scope" to "defaultScope" in 1.1.0.M4 -->
<property name="defaultScope" value="email,user_friends" />
</bean>
</list>
</property>
</bean>
Only difference is in the property 'scope' which has been renamed to 'defaultScope' in the latest Spring Social version. Thanks to Victor Lyuboslavsky for sharing the initial config.
来源:https://stackoverflow.com/questions/17110874/spring-social-get-user-email-while-authenticate