BasicAuthenticator in CB Lite does not seems to Authenticate (iOS - Swift)


#1

We are using following Couchbase Environment:

Community Edition 5.1.1 build 5723
Sync Gateway 2.1
Couchbase Lite 2.1 (iOS)

We have created the replicatorToPushPullChanges (Listed below) function to establish the replicator however our BasicAuthenticator doesn’t seem to be working. We are getting replicator status online regardless of incorrect user id BasicAuthenticator. Can anyone advise what may be wrong here?

 func replicatorToPushPullChanges()
    {
        
        let targetEndpoint = URLEndpoint(url: URL(string: "ws://<host>:4984/<bucket>")!)
        let replConfig = ReplicatorConfiguration(database: localDataBase, target: targetEndpoint)
        
        replConfig.replicatorType = .pushAndPull
        
        // Add authentication.
        replConfig.continuous =  true

       // This function does not really authenticate 
       replConfig.authenticator = BasicAuthenticator(username: "<user>", password: "<pass>")

      //Channel specific to the <user>
        replConfig.channels = ["12"]
        
         print("Couchbase Database Path:-\(localDataBase.path ?? "not found")")
        
        // Create replicator.
        replicator = Replicator(config: replConfig)
        
        // Listen to replicator change events.
        replicator.addChangeListener { (change) in
            if let error = change.status.error as NSError? {
                print("Replicator Error code :: \(error.code)")
            }
            if change.status.activity == .offline || change.status.activity == .stopped
            {
                MPReachability.shared.isReptlicatorOnline = false
            }
            else
            {
                MPReachability.shared.isReptlicatorOnline = true
            }
            print("Replicator status :%@ with date:%@",change.status.activity,Date())
        }
        // Start replication.
        replicator.start()
    }
    
}

Sync Gateway File:

{
    "log": ["*"],
    "adminInterface": "<host>:4985",
    "databases": {
"<bucket>": {
            "server": "http://<host>:8091",
            "bucket": "<bucket>",
            "username": "<user>",
            "password": "<pass>",
            "enable_shared_bucket_access": true,
            "use_views":true,
            "import_docs": "continuous",
            "sync": `function (doc, oldDoc) {
                if (doc.commChannel) {
                    channel(doc.commChannel);
                access(doc.<user>, doc.commChannels);
                }
            }`
        }
}

Our Users are created using REST API

curl -X POST "http://<host>:4985/<bucket>/_user/" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"name\": \"<user>\", \"password\": \"<pass>\", \"admin_channels\": [ \"12\" ], \"admin_roles\": [ \"companyAdmin\" ], \"email\": \"string\", \"disabled\": false}"


#2

Is the GUEST user active? There is a known issue that of GUEST is active that authentication will be ignored that is going to be fixed in 2.1.2