couchbaselabs / Couchbase-Lite-PhoneGap-Plugin

Plugin to install Couchbase Lite in your PhoneGap app on iOS or Android
183 stars 67 forks source link

Basic auth headers #18

Open tleyden opened 10 years ago

tleyden commented 10 years ago

Passing the username/pass into the url doesn't seem to work

Workaround:

Index.js

    function setupDb2(url, dbname) {

        log(typeof(window.request))

        var options = {
            url: 'http://foo:foo34324@localhost:5984/todo',
            headers: {
                'Authorization': "Basic Zm9vOmZvbzM0MzI0=="
            }
        };

        function callback(error, response, body) {
            if (!error && response.statusCode == 200) {
                log("error: " + error)
                log("response: " + response)
                log("body: " + body)

                if (!error && response.statusCode == 200) {
                    console.log(body) // Print the google web page.
                }

            }
        }

        window.request(options, callback);

Modules.js

    newHoax.url = myPax;
    window.request = request;  // <-- added
    return newHoax;

Related to https://github.com/couchbase/couchbase-lite-java-listener/issues/35

tleyden commented 10 years ago

OK after using these android jars: http://cl.ly/3P3D0Y364103

the request from phonegap -> cblite is working.

Logs: https://gist.github.com/tleyden/11308716

04-26 00:48:29.005 D/CordovaLog(12842): file:///android_asset/www/js/index.js: Line 863 : response: [object XMLHttpRequest]
04-26 00:48:29.005 I/Web Console(12842): response: [object XMLHttpRequest] at file:///android_asset/www/js/index.js:863
04-26 00:48:29.005 D/CordovaLog(12842): file:///android_asset/www/js/index.js: Line 863 : body: {"disk_size":106496,"update_seq":1,"doc_count":1,"instance_start_time":1398473308845000,"db_uuid":"fdb1fae0-de2d-4592-87c7-bd18c6355205","db_name":"todo"}
04-26 00:48:29.005 I/Web Console(12842): body: {"disk_size":106496,"update_seq":1,"doc_count":1,"instance_start_time":1398473308845000,"db_uuid":"fdb1fae0-de2d-4592-87c7-bd18c6355205","db_name":"todo"} at file:///android_asset/www/js/index.js:863
04-26 00:48:29.005 D/CordovaLog(12842): file:///android_asset/www/js/index.js: Line 621 : {"disk_size":106496,"update_seq":1,"doc_count":1,"instance_start_time":1398473308845000,"db_uuid":"fdb1fae0-de2d-4592-87c7-bd18c6355205","db_name":"todo"}
04-26 00:48:29.005 I/Web Console(12842): {"disk_size":106496,"update_seq":1,"doc_count":1,"instance_start_time":1398473308845000,"db_uuid":"fdb1fae0-de2d-4592-87c7-bd18c6355205","db_name":"todo"} at file:///android_asset/www/js/index.js:621
tleyden commented 10 years ago

The updated CBLite.java file is on the feature/issue_35_phonegap_security branch