protected void verifyProviderCredentialsForUser(WritableSession session, User user) {
    List<UserAuthData> authData = user.getAuthData();
    UserProviderCredentialsMap credentials = session.getUserProviderCredentials();

    if (credentials != null) {

      if (authData != null) {
        Map<AuthProviderType, UserProviderCredentials> validCreds =
            new LinkedHashMap<AuthProviderType, UserProviderCredentials>();
        for (UserAuthData userAuthData : authData) {
          UserProviderCredentials creds = credentials.get(userAuthData.getAuthProviderType());
          if (creds != null) {
            validCreds.put(userAuthData.getAuthProviderType(), creds);
          }
        }

        // Clear and reset
        credentials.removeAll();

        Set<Entry<AuthProviderType, UserProviderCredentials>> entrySet = validCreds.entrySet();

        for (Entry<AuthProviderType, UserProviderCredentials> entry : entrySet) {
          credentials.put(entry.getKey(), entry.getValue());
        }
      } else {
        credentials.removeAll();
      }

      // Set back to session
      session.setUserProviderCredentials(credentials);
    }
  }
  @Override
  public void clearSessionCache(Context context) {
    try {
      if (session != null) {

        UserProviderCredentialsMap userProviderCredentialsMap =
            session.getUserProviderCredentials();

        if (userProviderCredentialsMap != null) {
          Collection<UserProviderCredentials> values = userProviderCredentialsMap.values();
          for (UserProviderCredentials userProviderCredentials : values) {
            AuthProviderInfo authProviderInfo = userProviderCredentials.getAuthProviderInfo();
            if (authProviderInfo != null) {
              clear3rdPartySession(context, authProviderInfo.getType());
            }
          }
        }

        session = null;
      }
    } finally {
      if (userSystem != null) {
        userSystem.clearSession();
      }
    }
  }
 public boolean validateSessionAuthData(SocializeSession loaded, AuthProviderInfo info) {
   UserProviderCredentialsMap userProviderCredentialsMap = loaded.getUserProviderCredentials();
   if (userProviderCredentialsMap != null) {
     UserProviderCredentials userProviderCredentials =
         userProviderCredentialsMap.get(info.getType());
     if (userProviderCredentials != null
         && userProviderCredentials.getAuthProviderInfo().matches(info)) {
       return true;
     }
   }
   return false;
 }