Trouble authenticating to Sync Gateway with Facebook

So as a work around I’m manually using setCookie on the replicator.

Facebook Auth using Couchbase Lite .net

  • Setup sync gateway config

    "{ "facebook": { "register": true }}"
    
  • Create a webservice on the same sever as sync gateway to interact with the sync gateway Admin REST API

  • App pops up Facebook UI login dialog and get’s an access_token

  • App adds authenication to replication

    var auth = AuthenticatorFactory.CreateFacebookAuthenticator(access_token);
    push.Authenticator = auth;
    pull.Authenticator = auth;
    pull.Changed += ReplicationProgress;
    push.Changed += ReplicationProgress;
    pull.Start();
    push.Start();

  • couchbase lite creates user on sync gateway??

  • pull.Changed event triggers ReplicationProgress

  • Lack of session cookie throws System.Net.HttpStatusCode.Unauthorized

  • so get a session

    • Send Facebook Id to webservice which sends Facebook Id to sync gateway :4985/{db}/_session
    • Sync gateway returns session cookie info as json body to Webservice:
"{
"cookie_name": "SyncGatewaySession",
"expires": "2015-07-24T18:18:35.905685517Z",
"session_id": "c3be1c8f693440308b32cc32c3fae1938f613f9f"
}"
  • Webservice returns session cookie info to App
  • Uninitialize replicator
  • Replace replication with new replication, only this time setCookie
  "push.SetCookie (session ["cookie_name"].ToString (), 
  				session ["session_id"].ToString (), 
  				"/", 
  				DateTime.Parse (session ["expires"].ToString ()), 
  				false, false);
  pull.SetCookie (session ["cookie_name"].ToString (), 
  				session ["session_id"].ToString (), 
  				"/",
  				DateTime.Parse (session ["expires"].ToString ()), 
  				false, false);"

.

  • Since Replication usually is triggered multiple times while getting session, set boolean to prevent grabbing more than one session and needlessly re-initializing the replicator.

Let me know if I’m doing something egregiously wrong, thanks! :slight_smile: