【问题标题】:spring social get user email while authenticate春季社交在身份验证时获取用户电子邮件
【发布时间】:2013-06-14 14:30:53
【问题描述】:

我们正在使用 spring-social 将我们的应用程序集成到 facebook。 在 OAuth2AuthenticationService 中,范围为空。 我们将范围设置为表单上的输入。但它不起作用并且无法设置范围。 我们无法收到用户电子邮件。

有没有办法覆盖“OAuth2AuthenticationService”范围变量?

不是:Spring 社交版本是 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>

【问题讨论】:

  • 有同样的问题。如果我尝试使用/connect/facebook 而不是/auth/facebook 进行身份验证,我会看到以下警告变成异常:WARN : org.springframework.social.connect.web.ConnectController - Exception while handling OAuth2 callback (Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'name' cannot be found on null). Redirecting to facebook connection status page.

标签: spring-social


【解决方案1】:

在您的配置中,您需要将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}" />
                <property name="scope" value="email" />              
            </bean>
        </list>
    </property>
</bean>

这适用于 Spring Social 1.1.0.M3

【讨论】:

    【解决方案2】:

    要将上述 XML 配置与 Spring Social 1.1.0.RELEASE 一起使用,请使用次要编辑版本:

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

    唯一的区别在于属性“范围”已在最新的 Spring Social 版本中重命名为“默认范围”。感谢 Victor Lyuboslavsky 分享初始配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-01
      • 2022-01-01
      • 1970-01-01
      • 2014-09-08
      • 2022-07-22
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多