Search in sources :

Example 1 with User

use of org.springframework.social.facebook.api.User 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 User

use of org.springframework.social.facebook.api.User 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)

Aggregations

HashMap (java.util.HashMap)2 Facebook (org.springframework.social.facebook.api.Facebook)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