Closed jlxip closed 6 years ago
By the way, I know it can be absolutely disabled by setting 'authenticate' to null, but what I want is to get the first argument of the callback (type) and evaluate further actions (login) in runtime.
@jlxip have you tried:
const repo = new Server(path.resolve(__dirname, 'tmp'), {
autoCreate: true,
authenticate: (type, repo, username, password, next) => {
next();
}
});
I've tried that indeed, but the login is still required. However, as the program isn't evaluating the data, just allows any combination. What I would like to do is to avoid that the user and password are asked only when the type of the request is upload (clone or pull).
Edit: this probably requires an internal change of the package.
@jlxip I am having a hard time understanding what you mean when you say login is still required? Do you get an error?
This clone command (GitHub) requires no login: https://i.gyazo.com/8e4f034fcca05c294c25482ab7505bae.png
This one (node-git-server) does: https://i.gyazo.com/77a5ffd452e29a3df59a81a3a02ebc9e.png
I know you can avoid this by setting authenticate: null
, but I was wondering if there is any way to do this once the server knows which repository is the client trying to clone.
There isn't an exposed api at that level yet. The authenticate handler is the exposed portion atm.
I've implemented what I'm trying to do in a fork. Here's the pull request: https://github.com/gabrielcsapo/node-git-server/pull/29
Please, have a look at the minimal changes and, if you think they are good, merge them.
Here's a snippet of its power:
const Server = require('./index.js');
const path = require('path');
const repos = new Server(path.resolve(__dirname, 'tmp'), {
autoCreate: true,
authenticationHandler: (type, repo, next) => {
console.log(type + ' ' + repo);
//var doAuthenticate = true; // It is necessary to authenticate.
var doAuthenticate = false; // It's not necessary to authenticate. The repository is open to anyone who wants to clone it.
next(doAuthenticate)
},
authenticate: (type, repo, username, password, next) => {
console.log(username + ' doing ' + type + ' on ' + repo);
next();
}
});
const port = process.env.PORT || 7005;
repos.on('push', (push) => {
console.log('push ' + push.repo + '/' + push.commit
+ ' (' + push.branch + ')'
);
push.accept();
});
repos.on('fetch', (fetch) => {
console.log('fetch ' + fetch.commit);
fetch.accept();
});
repos.listen(port, () => {
console.log(`node-git-server running at http://localhost:${port}`)
});
And it works! https://i.gyazo.com/0a7c1f572f25b32bb3b468d8f397ff28.png
Further discussion on pr #29
Hey, I was wondering how could I disable the login so users could clone the repos easier.