跳到内容
Lenso
简体中文
Esc
navigateopen⌘Jpreview
本页内容

auth-password

将密码注册和登录添加到 auth 锚点。

当主机需要密码注册登录时安装auth-password。 这取决于auth

lenso module install auth
lenso module install auth-password
cargo run --bin migrate
lenso serve

安装auth-password后,通过密码注册并登录 路由:

curl -sS -X POST http://127.0.0.1:3000/v1/auth/password/register \
  -H 'content-type: application/json' \
  -d '{"identifier":"ada@example.com","password":"correct horse battery staple"}' | jq .

curl -sS -X POST http://127.0.0.1:3000/v1/auth/password/login \
  -H 'content-type: application/json' \
  -d '{"identifier":"ada@example.com","password":"correct horse battery staple"}' | jq .

当以下情况时,响应包括 user_idtokenexpires_atsession_id 令牌策略是数据库支持的会话。

user_idauth.users id。使用它作为产品参与者 id,或将其存储在 您自己的个人资料/账户表为 auth_user_idauth-password 不创建 单独的控制台用户。

重启后,验证:

  • /console 列出了 authauth-password
  • 运行时证据显示请求后的身份验证密码 HTTP 路由。
  • auth-password.token_strategy 出现在运行时配置中。

JWT模式

auth-password 默认为会话令牌。要发出 JWT,请设置运行时配置 auth-password.token_strategy=jwt 并提供一个秘密。对于本地主机配置, 更喜欢模块本地环境:

LENSO_MODULE_AUTH_PASSWORD__JWT_SECRET=dev-only-change-me

JWT 模式的运行时配置键包括:

  • auth-password.jwt_secret
  • auth-password.jwt_issuer
  • auth-password.jwt_audience
  • auth-password.jwt_ttl_hours

手动 Rust 组合

大多数主机应该使用 lenso module install。对于手写的手写 Host 组合, 使用 host 功能公开的公共内置函数:

use lenso::host::prelude::*;

pub fn host_composition() -> HostComposition {
    HostBuilder::new()
        .linked_module(builtins::auth())
        .linked_module(builtins::auth_password())
        .build()
}

更改链接模块组成后运行迁移:

cargo run --bin migrate

最后更新于 2026年8月1日

这个页面有帮助吗?