org.springframework.social.connect.Connection.fetchUserProfile()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中org.springframework.social.connect.Connection.fetchUserProfile()方法的一些代码示例,展示了Connection.fetchUserProfile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.fetchUserProfile()方法的具体详情如下:
包路径:org.springframework.social.connect.Connection
类名称:Connection
方法名:fetchUserProfile

Connection.fetchUserProfile介绍

[英]Fetch a normalized model of the user's profile on the provider system. Capable of exposing the user's name, email, and username. What is actually exposed depends on the provider and scope of this connection.
[中]在提供程序系统上获取用户配置文件的规范化模型。能够公开用户名、电子邮件和用户名。实际公开的内容取决于此连接的提供程序和范围。

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

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);
}

代码示例来源:origin: org.springframework.social/spring-social-web

private UserProfile getProfileIfConnected(Map<String, Object> model) {
  @SuppressWarnings("unchecked")
  List<Connection<?>> connections = (List<Connection<?>>) model.get("connections");
  if (connections != null) {
    for (Connection<?> connection : connections) {
      if (connection.getKey().getProviderId().equals(providerId)) {
        return connection.fetchUserProfile();
      }
    }
  }
  return null;
}

代码示例来源:origin: org.craftercms/crafter-profile-social-services-integration

/**
 * Creates a profile from the specified connection.
 *
 * @param connection the connection where to retrieve the profile info from
 *
 * @return
 */
public static Profile createProfileFromConnection(Connection<?> connection) {
  Profile profile = new Profile();
  addProviderProfileInfo(profile, connection.fetchUserProfile());
  return profile;
}

代码示例来源:origin: org.craftercms/crafter-profile-social-medial-integration

/**
 * Creates a profile from the specified connection.
 *
 * @param connection the connection where to retrieve the profile info from
 *
 * @return
 */
public static Profile createProfileFromConnection(Connection<?> connection) {
  Profile profile = new Profile();
  addProviderProfileInfo(profile, connection.fetchUserProfile());
  return profile;
}

代码示例来源:origin: org.zalando.zauth/spring-social-zauth

@Override
public String execute(final Connection<?> connection) {
  // or use more generic
  org.springframework.social.connect.UserProfile profile = connection.fetchUserProfile();
  final String username = profile.getUsername();
  Assert.hasText(username, "'username' should never be null or empty.");
  if (canAccess(username)) {
    return createOrUpdateUser(username);
  } else {
    return null;
  }
}

代码示例来源:origin: org.springframework.security.oauth.boot/spring-security-oauth2-autoconfigure

@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);
}

代码示例来源:origin: spring-projects/spring-security-oauth2-boot

@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);
}

代码示例来源:origin: socialsignin/spring-social-security

public P create(Connection<?> connection)
{
  P profile = instantiate();
  UserProfile userProfile = connection.fetchUserProfile();
  init(profile,userProfile,connection.createData());
  return profile;
  
}
public void init(P profile,UserProfile userProfile,ConnectionData connectionData)

代码示例来源:origin: org.craftercms/crafter-security-provider

UserProfile providerProfile = connection.fetchUserProfile();

代码示例来源:origin: com.jtbdevelopment.core-games/games-web

@Override
 public String execute(final Connection<?> connection) {
  try {
   Player player = playerRepository.findBySourceAndSourceId(connection.getKey().getProviderId(),
     connection.getKey().getProviderUserId());
   if (player != null) {
    return player.getIdAsString();
   } else {
    P p = playerFactory.newPlayer();
    p.setDisabled(false);
    p.setDisplayName(connection.fetchUserProfile().getName());
    p.setSource(connection.getKey().getProviderId());
    p.setSourceId(connection.getKey().getProviderUserId());
    p.setProfileUrl(connection.getProfileUrl());
    p.setImageUrl(connection.getImageUrl());
    p = playerRepository.save(p);
    return (p == null ? null : p.getIdAsString());
   }

  } catch (Exception e) {
   logger.warn("Experienced exception in AutoConnectionSignUp", e);
   return null;
  }

 }
}

相关文章