java - 如何使用 spring-social-security SocialAuthenticationFilter 指定 OAuth2 范围?

标签 java spring-security oauth-2.0 spring-social

我正在使用 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/

相关文章:

spring-mvc - 无状态的 Spring Security oauth2 提供者

java - WebSecurityConfigurerAdapter 中 httpBasic 和 jdbcAuthentication 的用户验证问题

Grails 安全登录设计问题以及库和数据库选择

java - 如何从已通过 OAuth2 身份验证的服务器使用 C2DM 向设备发送消息?

php - 无需用户交互的自动 Soundcloud PHP Api 身份验证

java - 对齐 <p :selectOneMenu> with <p:outputLabel> horizontally inside a table column (<p:panelGrid>)

java - 使用 String.split() 提取单词对

java.lang.NoClassDefFoundError 与 HBase 扫描

java - 通过JAVA.JDBC在MySQL中创建 "Event"

spring - Spring Boot 中 Zuul 代理 oAuth2 未授权