Search in sources :

Example 1 with UserProfile

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);
}
Also used : UserProfile(org.springframework.social.connect.UserProfile) AccessGrant(org.springframework.social.oauth2.AccessGrant)

Example 2 with UserProfile

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;
}
Also used : UserProfile(org.springframework.social.connect.UserProfile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with UserProfile

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;
}
Also used : UserProfile(org.springframework.social.connect.UserProfile) UserProfile(org.springframework.social.connect.UserProfile) Profile(org.craftercms.profile.api.Profile)

Example 4 with UserProfile

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);
}
Also used : User(com.furyviewer.domain.User) UserProfile(org.springframework.social.connect.UserProfile)

Example 5 with UserProfile

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);
}
Also used : UserProfile(org.springframework.social.connect.UserProfile) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest)

Aggregations

UserProfile (org.springframework.social.connect.UserProfile)6 User (com.dubion.domain.User)1 User (com.furyviewer.domain.User)1 Customer (org.broadleafcommerce.profile.core.domain.Customer)1 Profile (org.craftercms.profile.api.Profile)1 AccessGrant (org.springframework.social.oauth2.AccessGrant)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1