[英]Add custom login form to hapi-auth-basic
I use hapi-auth-basic to authenticate users. 我使用hapi-auth-basic对用户进行身份验证。 My question is how to add custom login form instead of using the basic form of the browser.
我的问题是如何添加自定义登录表单,而不是使用浏览器的基本表单。
You can bind the functionality of hapi-auth-basic
to any custom login form. 您可以将
hapi-auth-basic
的功能绑定到任何自定义登录表单。 You need to make sure that the properties get evaluated correctly on server side. 您需要确保在服务器端正确评估属性。
Here's a dedicated tutorial on basic authentication in hapi with hapi-auth-basic . 这是有关使用hapi-auth-basic在hapi中进行基本身份验证的专用教程。
Let's say you've a form like this: (it's very simple for illustration purposes) 假设您的表单如下:(出于说明目的,这非常简单)
<form action="/login" method="post">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" value="Log in">
</form>
On server side, you need to have multiple things in place: 在服务器端,您需要准备好许多东西:
validateFunc
that takes the input and evaluates it against your data set (like database) validateFunc
的身份验证策略,该策略接受输入并根据您的数据集(例如数据库)对其进行评估 POST
on path /login
, because the form sends the data to this endpoint /login
上方法POST
的路由处理程序,因为表单将数据发送到此端点 auth
config set with your strategy at the route handler auth
配置 What I mean is a setup like this: (again, simplified) 我的意思是这样的设置:(再次简化)
server.auth.strategy('simple', 'basic', { validateFunc: (request, username, password, callback) => {} })
server.route({
method: 'GET',
path: '/private-route',
config: {
auth: 'simple',
handler: function (request, reply) {
reply('Yeah! This message is only available for authenticated users!')
}
}
})
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.