@arkstack/ auth (韩语)
Arkstack的认证模块,提供核心认证和身份特征.
@arkstack/auth 提供 Arkstack 运行时驱动程序所使用的框架中立认证服务。 它支持认证验证,JWT支持的个人访问符,临时目的约束符,当前会话查询,两个要素认证帮助器,以及认证特定例外.
使用量
import { Auth } from '@arkstack/auth'
const auth = Auth.make()
const token = await auth.login(email, password)
const user = await auth.authorizeToken(token.token)
Auth解决您的应用程序 User 财务报告和审定财务报表 PersonalAccessToken 模型为 getModel() 从 @arkstack/common。 。 。 .
双向认证
import { TwoFactor } from '@arkstack/auth'
const setup = TwoFactor.createSetup(user)
await TwoFactor.setSecret(user.id, setup.secret)
if (TwoFactor.verifyCode(user, setup.secret, code)) {
const recoveryCodes = TwoFactor.generateBackupCodes()
await TwoFactor.setMethod(user.id, 'authenticator')
await TwoFactor.setEnabledAt(user.id)
await TwoFactor.writeRecoveryCodeHashes(user.id, await TwoFactor.hashBackupCodes(recoveryCodes))
}
持续使用2FA状态的应用程序应提供 UserTwoFactor 模型由 user_two_factors 页:1 起步器模板包括这个模型和迁移. 设定 TWO_FACTOR_ENCRYPTION_KEY 在存储验证器机密之前.
SMS 2FA 发行并存储挑战 @arkstack/auth,然后通过 @arkstack/notifications数字 :
import { Notification } from '@arkstack/notifications'
const issued = await TwoFactor.issueSmsCode(user, 'login')
await Notification.sms().recipient(user.phone).send('Your login code is {code}', undefined, undefined, {
code: issued.code,
})
配置短消息提供者为 notifications.drivers.sms.transport 和运输证书 notifications.transports.twilio 或者说 notifications.transports.africastalking。 。 。 .
驱动程序中间软件生活在运行时包中 :
import { auth } from '@arkstack/driver-express/middlewares'
import { auth as h3Auth } from '@arkstack/driver-h3/middlewares'
见完整设置的文档认证指南.