Skip to content

Commit 19520cc

Browse files
aralgabrielcsapo
andauthored
Improve authentication in example and readme (#78)
* 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]>
1 parent 7260530 commit 19520cc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,17 @@ const repos = new Server(path.resolve(__dirname, 'tmp'), {
131131
autoCreate: true,
132132
authenticate: ({type, repo, user}, next) => {
133133
if(type == 'push') {
134+
// Decide if this user is allowed to perform this action against this repo.
134135
user((username, password) => {
135136
console.log(username, password);
136-
next();
137+
if (accountName === '42' && password === '42') {
138+
next();
139+
} else {
140+
next('wrong password');
141+
}
137142
});
138143
} else {
144+
// Check these credentials are correct for this user.
139145
next();
140146
}
141147
}

example/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ const repos = new Server(path.normalize(path.resolve(__dirname, 'tmp')), {
2727
authenticate: ({ type, repo, user, headers }, next) => {
2828
console.log(type, repo, headers); // eslint-disable-line
2929
if(type == 'push') {
30+
// Decide if this user is allowed to perform this action against this repo.
3031
user((username, password) => {
3132
console.log(username, password); // eslint-disable-line
32-
next();
33+
if (accountName === '42' && password === '42') {
34+
next();
35+
} else {
36+
next('wrong password');
37+
}
3338
});
3439
} else {
40+
// Check these credentials are correct for this user.
3541
next();
3642
}
3743
}

0 commit comments

Comments
 (0)