Skip to content

Commit

Permalink
Improve authentication in example and readme (#78)
Browse files Browse the repository at this point in the history
* Improve authentication in example

The example app currently allows all requests. This small update demonstrates how to actually perform authentication, including rejection by calling `next()` with an error message string.

* Update README.md

Make the authentication example actually authenticate.

* Update README.md

* Update index.js

Co-authored-by: Gabriel Csapo <[email protected]>
  • Loading branch information
aral and gabrielcsapo authored Dec 4, 2021
1 parent 7260530 commit 19520cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,17 @@ const repos = new Server(path.resolve(__dirname, 'tmp'), {
autoCreate: true,
authenticate: ({type, repo, user}, next) => {
if(type == 'push') {
// Decide if this user is allowed to perform this action against this repo.
user((username, password) => {
console.log(username, password);
next();
if (accountName === '42' && password === '42') {
next();
} else {
next('wrong password');
}
});
} else {
// Check these credentials are correct for this user.
next();
}
}
Expand Down
8 changes: 7 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ const repos = new Server(path.normalize(path.resolve(__dirname, 'tmp')), {
authenticate: ({ type, repo, user, headers }, next) => {
console.log(type, repo, headers); // eslint-disable-line
if(type == 'push') {
// Decide if this user is allowed to perform this action against this repo.
user((username, password) => {
console.log(username, password); // eslint-disable-line
next();
if (accountName === '42' && password === '42') {
next();
} else {
next('wrong password');
}
});
} else {
// Check these credentials are correct for this user.
next();
}
}
Expand Down

0 comments on commit 19520cc

Please sign in to comment.