浏览器监控的多因素身份验证 (MFA)
Elastic Stack Serverless
多因素身份验证 (MFA) 为应用程序登录过程增加了一个重要的安全层,防止未经授权的访问。在 Synthetics 中,一个非常常见的用例是测试涉及受 MFA 保护的网站的用户旅程。
Synthetics 支持测试受基于时间的一次性密码 (TOTP) 保护的网站,这是一种常见的 MFA 方法,提供短时的一次性令牌以增强安全性。
要测试使用 TOTP 进行 MFA 的浏览器旅程,首先在目标应用程序中配置 Synthetics 身份验证器令牌。为此,请使用 Synthetics CLI 生成一次性密码 (OTP);请参阅 @elastic/synthetics totp <secret>
。
npx @elastic/synthetics totp <secret>
// prints
OTP Token: 123456
在您的应用程序中配置 Synthetics TOTP 身份验证后,您现在可以使用从 @elastic/synthetics
导入的 mfa
对象在 synthetics 浏览器旅程中使用 OTP 令牌。
import { journey, step, mfa} from '@elastic/synthetics';
journey('MFA Test', ({ page, params }) => {
step('Login using TOTP token', async () => {
// login using username and pass and go to 2FA in next page
const token = mfa.totp(params.MFA_SECRET);
await page.getByPlaceholder("token-input").fill(token)
});
});
对于使用脚本编辑器在 Synthetics UI 中创建的监控器,可以如下所示访问 mfa
对象
step('Login using 2FA', async () => {
const token = mfa.totp(params.MFA_SECRET);
await page.getByPlaceholder("token-input").fill(token)
});
注意
params.MFA_SECRET
将是用于在您的 Web 应用程序中注册 Synthetics 身份验证的编码密钥。