我为 facebook 配置了 spring social,并在我的应用程序中使用自定义UsersConnectionRepository
和ConnectionRepository
.
配置文件
@Configuration
public class SocialConfig extends SocialConfigurerAdapter{
...
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator factoryLocator) {
SecUsersConnectionRepository repository = new SecUsersConnectionRepository(factoryLocator, userRepository, userConnectionRepository);
return repository;
}
...
}
连接存储库实现
public class SecConnectionRepository implements ConnectionRepository {
...
@Override
public void addConnection(Connection<?> connection) {
UserConnection userConnection = userRepository.findConnectionBy(user, connection.getKey().getProviderId(), connection.getKey().getProviderUserId());
if (userConnection == null) {
...
userConnection.setProviderId(data.getProviderId());
userConnection.setProviderUserId(data.getProviderUserId());
userConnection.setDisplayName(data.getDisplayName());
userConnection.setProfileUrl(data.getProfileUrl());
userConnection.setImageUrl(data.getImageUrl());
...
} else {
throw new DuplicateConnectionException(connection.getKey());
}
}
当我添加我的 facebook 登录时,Connect<A>
接口对象获取profileUrl
,但 URL 是这种格式
https://www.facebook.com/profile.php?id=XXXXXXXXXXXXXXX&_rdr
如果我打开这个链接,浏览器会说
摇篮文件
buildscript {
repositories {
maven { url "https://repo.spring.io/libs-release" }
... }
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
}
apply plugin: 'java'
...
jar {...}
repositories {
...
maven { url "https://repo.spring.io/libs-release" }
}
dependencies {
...
compile("org.springframework.social:spring-social-facebook")
compile("org.springframework.social:spring-social-security")
... }
task wrapper(type: Wrapper) {...}
我在这里做错了什么?
解决方案
在春季更新 FB 库解决了这个问题。
compile("org.springframework.social:spring-social-facebook:2.0.1.RELEASE")