title: Couchbase facebook pull authenticator
body: <p>I am using couchbase mobile for an application and I want to use facebook for authentication. As per documentation, couchbase offers it's own implementation for authentication, the only required thing would be the token which I retrieve from the android facebook login flow.</p>
  
  <p>The code for Synchronize class looks something like this:</p>
  
  <pre><code>public class Synchronize {
  
  public Replication pullReplication;
  public Replication pushReplication;
  
  public static class Builder {
      public Replication pullReplication;
      public Replication pushReplication;
  
      public Builder(Database database, String url, Boolean continuousPull) {
  
          if (pullReplication == null &amp;&amp; pushReplication == null) {
  
              URL syncUrl;
              try {
                  syncUrl = new URL(url);
              } catch (MalformedURLException e) {
                  throw new RuntimeException(e);
              }
  
              pullReplication = database.createPullReplication(syncUrl);
              pullReplication.setContinuous(true);
  
              pushReplication = database.createPushReplication(syncUrl);
              pushReplication.setContinuous(true);
          }
      }
  
      public Builder facebookAuth(String token) {
  
          if (!TextUtils.isEmpty(token)) {
              Authenticator facebookAuthenticator = AuthenticatorFactory.createFacebookAuthenticator(token);
  
              pullReplication.setAuthenticator(facebookAuthenticator);
              pushReplication.setAuthenticator(facebookAuthenticator);
          }
  
          return this;
      }
  
      public Builder basicAuth(String username, String password) {
  
          Authenticator basicAuthenticator = AuthenticatorFactory.createBasicAuthenticator(username, password);
  
          pullReplication.setAuthenticator(basicAuthenticator);
          pushReplication.setAuthenticator(basicAuthenticator);
  
          return this;
      }
  
      public Builder addChangeListener(Replication.ChangeListener changeListener) {
          pullReplication.addChangeListener(changeListener);
          pushReplication.addChangeListener(changeListener);
  
          return this;
      }
  
      public Synchronize build() {
          return new Synchronize(this);
      }
  
  }
  
  private Synchronize(Builder builder) {
      pullReplication = builder.pullReplication;
      pushReplication = builder.pushReplication;
  }
  
  public void start() {
      pullReplication.start();
      pushReplication.start();
  }
  
  public void destroyReplications() {
      if (pullReplication != null &amp;&amp; pushReplication != null) {
          pullReplication.stop();
          pushReplication.stop();
          pullReplication.deleteCookie("SyncGatewaySession");
          pushReplication.deleteCookie("SyncGatewaySession");
          pullReplication = null;
          pushReplication = null;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And I use it like this:</p>
  
  <pre><code>...
  public void startReplicationSync(String facebookAccessToken) {
  
      if (sync != null) {
          sync.destroyReplications();
      }
  
      final String url = BuildConfig.URL_HOST + ":" + BuildConfig.URL_PORT + "/" + DATABASE_NAME;
      sync = new Synchronize.Builder(databaseManager.getDatabase(), url, true)
              .facebookAuth(facebookAccessToken)
              .addChangeListener(getReplicationChangeListener())
              .build();
      sync.start();
  
  }
  ...
  </code></pre>
  
  <p>My sync gateway json config file:</p>
  
  <pre><code>{
  "interface":":4984",       
  "adminInterface":":4985",
  "log":["REST"],
  "facebook":{
    "register" : true
  },
  "databases":{               
  "sync_gateway":{
  "server":"http://localhost:8091",
  "bucket":"sync_gateway",
  "users": {
      "GUEST": {"disabled": false}
  },
  "sync":`function(doc) {channel(doc.channels);}`
  }
  }
  }
  </code></pre>
  
  <p>I also tried with "GUEST": {"disabled": true}, no luck</p>
  
  <p>My problem is that if I do this </p>
  
  <pre><code>pullReplication.setAuthenticator(facebookAuthenticator);
  pushReplication.setAuthenticator(facebookAuthenticator);
  </code></pre>
  
  <p><strong>Nothing will ever get replicated/pulled from the server. However if I don't set an authenticator, everything is pulled. Is it something I am doing wrong?</strong> I really need to use the authenticator in order to prevent some documents to not being replicated for non-authenticated users.</p>
  
  <p>Note! The token is good, as if I am looking in the users section of sync gateway admin, I can see the right profile id of the logged in user token I passed to the couchbase facebook authenticator.</p>