Document requirement for cookie path when using paths other than /login
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript
- Lĩnh vực
- authentication, documentation
Hướng nghiên cứu
Trước tiên, hãy xem lại tài liệu về chiến lược cookie và ví dụ cấu hình trong issue này. Ghi lại rằng việc sử dụng đường dẫn đăng nhập khác với /login yêu cầu đặt đường dẫn cookie thành /, với ví dụ /foo/login; được xem là hoàn thành khi yêu cầu đã rõ ràng trong tài liệu liên quan.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Context
- node version: 14.15.4
- module version: 11.0.2
What are you trying to achieve or the steps to reproduce ?
We wasted several hours trying to configure our login page to be something other than /login, in the example below we tried using /foo.login. After asking in the Hapi slack channel, it was pointed out to us that if you do not assign the cookie a path, it defaults to null and only works with the path /login and therefore breaks the code if you do not specify it as / for a different path. It would be appreciated if the documentation was updated with this an example or highlight that the path must be noted if you wish to using anything other than the default.
const Bcrypt = require('bcrypt');
// create a server with a host and port
const server = new Hapi.Server({
host: 'localhost',
port: 3000
})
const users = [
{
username: 'john',
password: '$2a$10$iqJSHD.BGr0E2IxQwYgJmeP3NvhPrXAeLSaGCj6IR/XU5QtjVu5Tm', // 'secret'
name: 'John Doe',
id: '2133d32a'
}
];
async function start () {
await server.register(require('@hapi/cookie'));
server.auth.strategy('session', 'cookie', {
cookie: {
name: 'sid-example',
password: '!wsYhFA*C2U6nz=Bu^%A@^F#SF3&kSR6',
isSecure: false,
path: '/'
},
redirectTo: '/foo/login',
validateFunc: async (request, session) => {
const account = await users.find(
(user) => (user.id === session.id)
);
if (!account) {
return { valid: false };
}
return { valid: true, credentials: account };
}
});
server.auth.default('session');
server.route([
{
method: 'GET',
path: '/',
handler: function (request, h) {
return 'Welcome to the restricted home page!';
}
},
{
method: 'GET',
path: '/foo/login',
handler: function (request, h) {
return ` <html>
<head>
<title>Login page</title>
</head>
<body>
<h3>Please Log In</h3>
<form method="post" action="/foo/login">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br/>
<input type="submit" value="Login"></form>
</body>
</html>`;
},
options: {
auth: false
}
},
{
method: 'POST',
path: '/foo/login',
handler: async (request, h) => {
const { username, password } = request.payload;
const account = users.find(
(user) => user.username === username
);
if (!account || !(await Bcrypt.compare(password, account.password))) {
return h.view('/foo/login');
}
request.cookieAuth.set({ id: account.id });
return h.redirect('/');
},
options: {
auth: {
mode: 'try'
}
}
}
]);
// start your server
try {
await server.start()
} catch (err) {
console.error(err)
process.exit(1)
}
console.log('Server running at: ', server.info.uri)
}
start()
- Ngôn ngữ chính
- JavaScript
- Star
- 229
- Fork
- 99
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của hapijs/cookie
-
support
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
-
ttl和keepAlive功能存在bugĐang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
-
feature
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
support
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
support
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
Tất cả issue của hapijs/cookie
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
obsidianmd/obsidian-help#1169 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[docs] RELEASE.md: wrong branch name, no check that the prepare PR merged with the right subject, manual publish stepCó thể đã có người làm @albertteoh đã nhận hôm nay. Đang mởdocumentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
jaegertracing/jaeger-ui#4739 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
keepassxreboot/keepassxc-browser#3159 · 1 bình luận ·
-
Add: ESP 2 RSĐang mởapproved check:passed feeds:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 67/100