use of org.springframework.social.connect.UserProfile in project spring-boot by spring-projects.
the class SpringSocialTokenServices method loadAuthentication.
@Override
public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException, InvalidTokenException {
AccessGrant accessGrant = new AccessGrant(accessToken);
Connection<?> connection = this.connectionFactory.createConnection(accessGrant);
UserProfile user = connection.fetchUserProfile();
return extractAuthentication(user);
}
use of org.springframework.social.connect.UserProfile in project theskeleton by codenergic.
the class RegistrationController method registrationView.
@GetMapping
public String registrationView(RegistrationForm registrationForm, WebRequest request) {
Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
if (connection != null) {
UserProfile profile = connection.fetchUserProfile();
registrationForm.setUsername(profile.getUsername());
registrationForm.setEmail(profile.getEmail());
}
return REGISTRATION;
}
use of org.springframework.social.connect.UserProfile in project profile by craftercms.
the class ConnectionUtils method createProfile.
/**
* Creates a profile from the specified connection.
*
* @param connection the connection where to retrieve the profile info from
*
* @return the created profile
*/
public static Profile createProfile(Connection<?> connection) {
Profile profile = new Profile();
UserProfile providerProfile = connection.fetchUserProfile();
String email = providerProfile.getEmail();
if (StringUtils.isEmpty(email)) {
throw new IllegalStateException("No email included in provider profile");
}
String username = providerProfile.getUsername();
if (StringUtils.isEmpty(username)) {
username = email;
}
String firstName = providerProfile.getFirstName();
String lastName = providerProfile.getLastName();
String displayName;
if (StringUtils.isNotEmpty(connection.getDisplayName())) {
displayName = connection.getDisplayName();
} else {
displayName = firstName + " " + lastName;
}
profile.setUsername(username);
profile.setEmail(email);
profile.setAttribute(FIRST_NAME_ATTRIBUTE_NAME, firstName);
profile.setAttribute(LAST_NAME_ATTRIBUTE_NAME, lastName);
profile.setAttribute(DISPLAY_NAME_ATTRIBUTE_NAME, displayName);
if (StringUtils.isNotEmpty(connection.getImageUrl())) {
profile.setAttribute(AVATAR_LINK_ATTRIBUTE_NAME, connection.getImageUrl());
}
return profile;
}
use of org.springframework.social.connect.UserProfile in project FuryViewer by TheDoctor-95.
the class SocialService method createSocialUser.
public void createSocialUser(Connection<?> connection, String langKey) {
if (connection == null) {
log.error("Cannot create social user because connection is null");
throw new IllegalArgumentException("Connection cannot be null");
}
UserProfile userProfile = connection.fetchUserProfile();
String providerId = connection.getKey().getProviderId();
String imageUrl = connection.getImageUrl();
User user = createUserIfNotExist(userProfile, langKey, providerId, imageUrl);
createSocialConnection(user.getLogin(), connection);
mailService.sendSocialRegistrationValidationEmail(user, providerId);
}
use of org.springframework.social.connect.UserProfile in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafSocialRegisterController method register.
// Pre-populate portions of the RegisterCustomerForm from ProviderSignInUtils.getConnection();
public String register(RegisterCustomerForm registerCustomerForm, HttpServletRequest request, HttpServletResponse response, Model model) {
Connection<?> connection = ProviderSignInUtils.getConnection(new ServletWebRequest(request));
if (connection != null) {
UserProfile userProfile = connection.fetchUserProfile();
Customer customer = registerCustomerForm.getCustomer();
customer.setFirstName(userProfile.getFirstName());
customer.setLastName(userProfile.getLastName());
customer.setEmailAddress(userProfile.getEmail());
if (isUseEmailForLogin()) {
customer.setUsername(userProfile.getEmail());
} else {
customer.setUsername(userProfile.getUsername());
}
}
return super.register(registerCustomerForm, request, response, model);
}
Aggregations