【问题标题】:Update Facebook profile with Spring Social使用 Spring Social 更新 Facebook 个人资料
【发布时间】:2016-01-07 13:10:33
【问题描述】:

我在 Spring Social 的网站上使用 Facebook 登录。我还在我的数据库中为每个 Facebook 用户创建了一个具有特定应用程序首选项的用户。用户登录后,我想在我的数据库中更新他的个人信息,例如姓名和电子邮件。最好的方法是什么?如何做?

【问题讨论】:

    标签: spring-social spring-social-facebook


    【解决方案1】:

    我终于实现了ApplicationListener<InteractiveAuthenticationSuccessEvent>,在用户登录后调用。

    @Override
    public void onApplicationEvent(InteractiveAuthenticationSuccessEvent authEvent) {
        Authentication auth = authEvent.getAuthentication();
        if (auth instanceof SocialAuthenticationToken && auth.getPrincipal() instanceof User) {
            // every time a user authenticates through a social network, then we update his info from there
            User user = (User)auth.getPrincipal();
            // ... update user using ((SocialAuthenticationToken)auth).getConnection()
            // ... and save it
        }
    }
    

    也可以通过覆盖ConnectionRepository#updateConnection来做到这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      • 2013-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多