I configured spring social for facebook and also the spring social authentication in my application with a custom UsersConnectionRepository
and ConnectionRepository
.
Configuration file
@Configuration
public class SocialConfig extends SocialConfigurerAdapter{
...
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator factoryLocator) {
SecUsersConnectionRepository repository = new SecUsersConnectionRepository(factoryLocator, userRepository, userConnectionRepository);
return repository;
}
...
}
Connection Repository implementation
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());
}
}
When I add my facebook login, the Connect<A>
interface object fetch the profileUrl
, But the URL is in this format
https://www.facebook.com/profile.php?id=XXXXXXXXXXXXXXX&_rdr
If I open up this link the browser is says
Gradle file
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) {...}
What am I doing wrong here?
SOLUTION
updating the FB libary in spring solved the issue.
compile("org.springframework.social:spring-social-facebook:2.0.1.RELEASE")
Check if you're using the most recent version of Spring Social. The profileUrl should nowadays have the scheme
https://www.facebook.com/app_scoped_user_id/{app_scoped_user_id}/
where {app_scoped_user_id}
is the actual app-scoped user id.
See