@ApiOperation(
      value = "SNS 기반 회원 가입시 필요한 회원 프로필 정보",
      produces = "application/json",
      response = UserProfileForm.class)
  @RequestMapping(value = "/social/attempted", method = RequestMethod.GET)
  public UserProfileForm loginSocialUser(NativeWebRequest request) {

    Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);

    if (Objects.isNull(connection)) throw new ServiceException(ServiceError.CANNOT_GET_SNS_PROFILE);

    ConnectionKey connectionKey = connection.getKey();

    CommonConst.ACCOUNT_TYPE convertProviderId =
        CommonConst.ACCOUNT_TYPE.valueOf(connectionKey.getProviderId().toUpperCase());
    UserProfile existUser =
        userService.findUserProfileByProviderIdAndProviderUserId(
            convertProviderId, connectionKey.getProviderUserId());
    org.springframework.social.connect.UserProfile socialProfile = connection.fetchUserProfile();

    String username = null;
    if (Objects.nonNull(socialProfile.getName())) {
      username = socialProfile.getName();
    } else if (Objects.nonNull(socialProfile.getUsername())) {
      username = socialProfile.getUsername();
    } else {
      if (Objects.nonNull(socialProfile.getFirstName())) {
        username = socialProfile.getFirstName();
      }
      if (Objects.nonNull(socialProfile.getLastName())) {
        username =
            Objects.isNull(username)
                ? socialProfile.getLastName()
                : ' ' + socialProfile.getLastName();
      }
    }

    UserProfileForm user = new UserProfileForm();
    user.setEmail(socialProfile.getEmail());
    user.setUsername(username);

    if (Objects.nonNull(existUser)) {
      user.setId(existUser.getId());
      user.setAbout(existUser.getAbout());

      if (Objects.nonNull(existUser.getSupportFC()))
        user.setFootballClub(existUser.getSupportFC().getId());
    }

    return user;
  }
  @ApiOperation(
      value = "SNS 기반 로그인",
      produces = "application/json",
      response = EmptyJsonResponse.class)
  @RequestMapping(value = "/login/social/{providerId}", method = RequestMethod.POST)
  public EmptyJsonResponse loginSocialUser(
      @PathVariable String providerId,
      @Valid @RequestBody LoginSocialUserForm form,
      NativeWebRequest request) {

    CommonConst.ACCOUNT_TYPE convertProviderId =
        CommonConst.ACCOUNT_TYPE.valueOf(providerId.toUpperCase());

    AccessGrant accessGrant = new AccessGrant(form.getAccessToken());
    Connection<?> connection = null;

    switch (convertProviderId) {
      case FACEBOOK:
        connection = facebookConnectionFactory.createConnection(accessGrant);
        break;
      case DAUM:
        connection = daumConnectionFactory.createConnection(accessGrant);
        break;
    }

    assert connection != null;
    ConnectionKey connectionKey = connection.getKey();

    Set<String> userIds =
        usersConnectionRepository.findUserIdsConnectedTo(
            providerId,
            new HashSet<>(Collections.singletonList(connectionKey.getProviderUserId())));
    User existUser =
        userService.findOneByProviderIdAndProviderUserId(
            convertProviderId, connectionKey.getProviderUserId());

    // 로그인 처리.
    if (!userIds.isEmpty()) {
      userService.signInSocialUser(existUser);

      return EmptyJsonResponse.newInstance();
    }

    // SNS 신규 가입.
    ProviderSignInAttempt signInAttempt = new ProviderSignInAttempt(connection);
    sessionStrategy.setAttribute(request, ProviderSignInAttempt.SESSION_ATTRIBUTE, signInAttempt);

    throw new ServiceException(ServiceError.NOT_REGISTER_WITH_SNS);
  }