【发布时间】:2016-01-07 13:10:33
【问题描述】:
我在 Spring Social 的网站上使用 Facebook 登录。我还在我的数据库中为每个 Facebook 用户创建了一个具有特定应用程序首选项的用户。用户登录后,我想在我的数据库中更新他的个人信息,例如姓名和电子邮件。最好的方法是什么?如何做?
【问题讨论】:
标签: spring-social spring-social-facebook
我在 Spring Social 的网站上使用 Facebook 登录。我还在我的数据库中为每个 Facebook 用户创建了一个具有特定应用程序首选项的用户。用户登录后,我想在我的数据库中更新他的个人信息,例如姓名和电子邮件。最好的方法是什么?如何做?
【问题讨论】:
标签: spring-social spring-social-facebook
我终于实现了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来做到这一点。
【讨论】: