我正在使用 Spring Social 和 Spring Security 来验证用户身份并在我的 Web 应用程序上自动创建本地帐户。如何提供 OAuth2 范围
进行身份验证?
在 spring-social-samples ,我不知道 scope
应该去哪里。
<bean id="socialAuthenticationFilter" class="org.springframework.social.security.SocialAuthenticationFilter"
c:_0-ref="authenticationManager"
c:_1-ref="userIdSource"
c:_2-ref="usersConnectionRepository"
c:_3-ref="connectionFactoryLocator"
p:signupUrl="/spring-social-showcase/signup"
p:rememberMeServices-ref="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0" />
<bean id="socialAuthenticationProvider" class="org.springframework.social.security.SocialAuthenticationProvider"
c:_0-ref="usersConnectionRepository"
c:_1-ref="socialUsersDetailService" />
scope
的一个具体用例是让用户通过 Facebook 进行身份验证,然后获取用户的 Facebook 电子邮件 (scope="email"
) 以创建本地帐户.
最佳答案
在您的配置中,您需要将 scope
指定为 FacebookAuthenticationService
的属性。这是处理对 auth/facebook
在 XML 配置中,而不是:
<facebook:config app-id="${facebook.clientId}" app-secret="${facebook.clientSecret}"/>
用途:
<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}" />
<!-- Important: The next property name changed from "scope" to "defaultScope" in 1.1.0.M4 -->
<property name="scope" value="email" />
</bean>
</list>
</property>
</bean>
这适用于 Spring Social 1.1.0.M3
关于java - 如何使用 spring-social-security SocialAuthenticationFilter 指定 OAuth2 范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17732858/