以下是我目前所拥有的内容:
我的问题是我希望这些API被多个客户端使用,但Facebook登录的方式现在,它在移动设备上运行良好(在网站上运行良好)。
以下是移动设备:
可以这样做吗?或者我是否必须编写自己的API以持久保存用户连接?
感谢任何帮助!
答案 0 :(得分:10)
我遇到了完全相同的问题,这就是我如何使它发挥作用。你可能在某处有一个SocialConfigurer,其中包含以下内容:
@Configuration
@EnableSocial
public class SocialConfig implements SocialConfigurer {
@Autowired
private DataSource dataSource;
@Bean
public FacebookConnectionFactory facebookConnectionFactory() {
FacebookConnectionFactory facebookConnectionFactory = new FacebookConnectionFactory("AppID", "AppSecret");
facebookConnectionFactory.setScope("email");
return facebookConnectionFactory;
}
@Override
public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
cfConfig.addConnectionFactory(facebookConnectionFactory());
}
@Override
public UserIdSource getUserIdSource() {
return new AuthenticationNameUserIdSource();
}
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText());
}
// Other @Bean maybe ...
}
从这里开始,您可以在Controller / RestController中添加一个映射,其中包含您将发送到服务器的令牌的RequestParam:
@Autowired
private FacebookConnectionFactory facebookConnectionFactory;
@Autowired
private UsersConnectionRepository usersConnectionRepository;
@RequestMapping(value = "/my-facebook-url", method = RequestMethod.POST)
public String fb(@RequestParam String token) {
AccessGrant accessGrant = new AccessGrant(token);
Connection<Facebook> connection = facebookConnectionFactory.createConnection(accessGrant);
UserProfile userProfile = connection.fetchUserProfile();
usersConnectionRepository.createConnectionRepository(userProfile.getEmail()).addConnection(connection);
// ...
return "Done";
}
有用的参考资料