【发布时间】:2017-02-16 12:05:24
【问题描述】:
我在使用spring-social 获取id 和name 以外的参数时遇到问题。
依赖关系:
<!-- Spring Social -->
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-config</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-web</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<!-- Spring Social Facebook -->
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
配置:
<security:http ...>
...
<security:custom-filter before="PRE_AUTH_FILTER" ref="socialAuthenticationFilter" />
...
</security:http>
<security:authentication-manager alias="authenticationManager">
...
<security:authentication-provider ref="socialAuthenticationProvider" />
</security:authentication-manager>
<bean id="socialAuthenticationProvider" class="org.springframework.social.security.SocialAuthenticationProvider">
<constructor-arg ref="inMemoryUsersConnectionRepository"/>
<constructor-arg ref="socialUserDetailsService"/>
</bean>
<bean id="inMemoryUsersConnectionRepository"
class="org.springframework.social.connect.mem.InMemoryUsersConnectionRepository">
<constructor-arg name="connectionFactoryLocator" ref="connectionFactoryLocator"/>
<property name="connectionSignUp" ref="connectionSignUp"/>
</bean>
<bean id="connectionFactoryLocator"
class="org.springframework.social.security.SocialAuthenticationServiceRegistry">
<property name="authenticationServices">
<list>
<ref bean="facebookAuthenticationService"/>
</list>
</property>
</bean>
<bean id="socialAuthenticationFilter" class="org.springframework.social.security.SocialAuthenticationFilter">
<constructor-arg name="authManager" ref="authenticationManager"/>
<constructor-arg name="userIdSource" ref="userIdSource"/>
<constructor-arg name="usersConnectionRepository" ref="inMemoryUsersConnectionRepository"/>
<constructor-arg name="authServiceLocator" ref="connectionFactoryLocator"/>
<property name="authenticationSuccessHandler" ref="loginGuidAuthenticationSuccessHandler"/>
</bean>
<bean id="userIdSource" class="org.springframework.social.security.AuthenticationNameUserIdSource"/>
<bean id="facebookAuthenticationService"
class="org.springframework.social.facebook.security.FacebookAuthenticationService">
<constructor-arg name="apiKey" value="<myKey>"/>
<constructor-arg name="appSecret" value="<mySecret>"/>
<property name="defaultScope" value="email"/>
</bean>
<bean id="connectionSignUp" class="my.package.DefaultConnectionSignUp"/>
我对一些必需的服务有自己的实现,但我认为这些服务并不相关。当我在ConnectionSignUp 的实现中调试execute 方法时,除了name 和id 之外,所有用户字段都为空。
@Override
public String execute(Connection<?> connection) {
Connection<Facebook> fbConnection = (Connection<Facebook>) connection;
fbConnection.getApi().userOperations().getUserProfile().getEmail(); //null
fbConnection.getApi().userOperations().getUserProfile().getFirstName(); //null
fbConnection.fetchUserProfile().getEmail(); //null
fbConnection.fetchObject("me", User.class); //email == null
...
}
我的jsp表单:
<form name='facebookSocialloginForm'
action="<c:url value='/auth/facebook' />" method='POST'>
<input type="hidden" name="scope"
value="public_profile,email,user_about_me,user_birthday,user_likes"/>
...
</form>
我可以访问用户私人posts 和likes。在我的 Facebook 帐户上,它说该应用程序可以访问电子邮件和其他信息。
有什么建议吗?如果我错过了一些重要的事情,请询问,我会提供更多信息。
【问题讨论】:
标签: java spring spring-security spring-social spring-social-facebook