jaredhanson / passport-http

HTTP Basic and Digest authentication strategies for Passport and Node.js.

Home Page:https://www.passportjs.org/packages/passport-http/?utm_source=github&utm_medium=referral&utm_campaign=passport-http&utm_content=about

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to make an ajax call using basic auth

ekelvin opened this issue · comments

I am trying to use basicauth for ajax cors but the user and the password in the node server passport-http come undefined. What I am missing in here?

app.use(passport.initialize());
app.use(allowCrossDomain);
app.use(app.router);

where allowCrossDomain is for allowing cors requests

 $.ajax
        ({
            type: "POST",
            url: "https://kelvin-new:8000/admin",
            dataType: 'json',
            crossDomain: true,
            async: false,
            username: $("#login#username").val(),
            password: $("#login#password").val(),
            beforeSend: function(xhr){
            xhr.setRequestHeader("Authorization", "Basic " + btoa($("#login#username").val() + ":" + $("#login#password").val()))
            },
            data: '{ "comment" }',
            withCredentials: true,
            done: function (res){
                alert('Thanks for your comment!');
            },
            error: function(error) {
                alert(error.statusText);
            }
        });

my nobby mistake :(