gabrielcsapo / node-git-server

🎡 A configurable git server written in Node.js
https://gabrielcsapo.github.io/node-git-server
MIT License
253 stars 73 forks source link

How is authentication supposed to work? #66

Closed neilyoung closed 4 years ago

neilyoung commented 4 years ago

In your examples you are not too specific how your authenticate function is supposed to work.

You are just tracing the username/password and proceed.

What am I supposed to do in order to achieve a proper authentication? So far I tried this:

Server

const repos = new Server(path.resolve(__dirname, 'tmp'), {
    autoCreate: true,
    authenticate: ({ type, repo, username, password, headers }, next) => {
        console.log(type, repo, username, password);
        return new Promise((resolve, reject) => {
            if (username === 'foo') {
                return resolve();
            }
            return reject("sorry you don't have access to this content");
        });
    }
});

The client calls this like so:

~/Documents/tmp/git $ git push http://kms:7005/what master
Username for 'http://kms:7005': foo
Password for 'http://foo@kms:7005': 
remote: sorry you don't have access to this content
fatal: Authentication failed for 'http://kms:7005/what/'

I'm getting asked client side for username/password, enter that, but get a rejection. Server side this is logged:

push what undefined undefined

neilyoung commented 4 years ago

OK, figured it out:

const repos = new Server(path.resolve(__dirname, 'tmp'), {
    autoCreate: true,
    authenticate: ({ type, repo, user, headers }, next) => {
        user((username, password) => {
            console.log(username, password);
            if (username == "foo" && password == "bar")
                next()
            else
                next("authentication failed")
        });
    }
});
felixmariotto commented 4 years ago

This definitely needs more doc

neilyoung commented 4 years ago

But it works well :)