Search in sources :

Example 1 with Facebook

use of org.springframework.social.facebook.api.Facebook in project ORCID-Source by ORCID.

the class SocialAjaxAuthenticationSuccessHandler method retrieveUserDetails.

private Map<String, String> retrieveUserDetails(SocialType connectionType) {
    Map<String, String> userMap = new HashMap<String, String>();
    if (SocialType.FACEBOOK.equals(connectionType)) {
        Facebook facebook = socialContext.getFacebook();
        User user = facebook.fetchObject("me", User.class, "id", "email", "name");
        userMap.put("providerUserId", user.getId());
        userMap.put("userName", user.getName());
        userMap.put("email", user.getEmail());
    } else if (SocialType.GOOGLE.equals(connectionType)) {
        Google google = socialContext.getGoogle();
        Person person = google.plusOperations().getGoogleProfile();
        userMap.put("providerUserId", person.getId());
        userMap.put("userName", person.getDisplayName());
        userMap.put("email", person.getAccountEmail());
    }
    return userMap;
}
Also used : Google(org.springframework.social.google.api.Google) User(org.springframework.social.facebook.api.User) HashMap(java.util.HashMap) Facebook(org.springframework.social.facebook.api.Facebook) Person(org.springframework.social.google.api.plus.Person)

Example 2 with Facebook

use of org.springframework.social.facebook.api.Facebook in project ORCID-Source by ORCID.

the class SocialController method retrieveUserDetails.

private Map<String, String> retrieveUserDetails(SocialType connectionType) {
    Map<String, String> userMap = new HashMap<String, String>();
    if (SocialType.FACEBOOK.equals(connectionType)) {
        Facebook facebook = socialContext.getFacebook();
        User user = facebook.fetchObject("me", User.class, "id", "email", "name", "first_name", "last_name");
        userMap.put("providerUserId", user.getId());
        userMap.put("userName", user.getName());
        userMap.put("email", user.getEmail());
        userMap.put("firstName", user.getFirstName());
        userMap.put("lastName", user.getLastName());
    } else if (SocialType.GOOGLE.equals(connectionType)) {
        Google google = socialContext.getGoogle();
        Person person = google.plusOperations().getGoogleProfile();
        userMap.put("providerUserId", person.getId());
        userMap.put("userName", person.getDisplayName());
        userMap.put("email", person.getAccountEmail());
        userMap.put("firstName", person.getGivenName());
        userMap.put("lastName", person.getFamilyName());
    }
    return userMap;
}
Also used : Google(org.springframework.social.google.api.Google) User(org.springframework.social.facebook.api.User) HashMap(java.util.HashMap) Facebook(org.springframework.social.facebook.api.Facebook) Person(org.springframework.social.google.api.plus.Person)

Example 3 with Facebook

use of org.springframework.social.facebook.api.Facebook in project engine by craftercms.

the class ConfigAwareConnectionFactoryLocatorTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    CacheTemplateMockUtils.setUpWithNoCaching(cacheTemplate);
    ConfigurationParser<?> configParserStub = new FacebookConnectionFactoryConfigParser() {

        @Override
        protected ConnectionFactory<Facebook> createFacebookConnectionFactory(String appId, String appSecret) {
            return new FacebookConnectionFactoryStub(appId, appSecret);
        }
    };
    locator = new ConfigAwareConnectionFactoryLocator();
    locator.setCacheTemplate(cacheTemplate);
    locator.setDefaultLocator(new ConnectionFactoryRegistry());
    locator.setConfigParsers(Arrays.<ConfigurationParser<?>>asList(configParserStub));
}
Also used : ConfigAwareConnectionFactoryLocator(org.craftercms.engine.util.spring.social.ConfigAwareConnectionFactoryLocator) FacebookConnectionFactoryConfigParser(org.craftercms.engine.util.config.impl.FacebookConnectionFactoryConfigParser) Facebook(org.springframework.social.facebook.api.Facebook) ConnectionFactoryRegistry(org.springframework.social.connect.support.ConnectionFactoryRegistry) Before(org.junit.Before)

Example 4 with Facebook

use of org.springframework.social.facebook.api.Facebook in project ORCID-Source by ORCID.

the class SocialContext method isConnectedFacebookUser.

private boolean isConnectedFacebookUser(String userId) {
    ConnectionRepository connectionRepo = connectionRepository.createConnectionRepository(userId);
    Connection<Facebook> facebookConnection = connectionRepo.findPrimaryConnection(Facebook.class);
    return facebookConnection != null;
}
Also used : ConnectionRepository(org.springframework.social.connect.ConnectionRepository) UsersConnectionRepository(org.springframework.social.connect.UsersConnectionRepository) Facebook(org.springframework.social.facebook.api.Facebook)

Aggregations

Facebook (org.springframework.social.facebook.api.Facebook)4 HashMap (java.util.HashMap)2 User (org.springframework.social.facebook.api.User)2 Google (org.springframework.social.google.api.Google)2 Person (org.springframework.social.google.api.plus.Person)2 FacebookConnectionFactoryConfigParser (org.craftercms.engine.util.config.impl.FacebookConnectionFactoryConfigParser)1 ConfigAwareConnectionFactoryLocator (org.craftercms.engine.util.spring.social.ConfigAwareConnectionFactoryLocator)1 Before (org.junit.Before)1 ConnectionRepository (org.springframework.social.connect.ConnectionRepository)1 UsersConnectionRepository (org.springframework.social.connect.UsersConnectionRepository)1 ConnectionFactoryRegistry (org.springframework.social.connect.support.ConnectionFactoryRegistry)1