加载中

浏览器监视器的多因素身份验证 (MFA)

多因素身份验证 (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 身份验证的编码密钥。

© . This website operates independently and is not affiliated with or endorsed by Elasticsearch B.V. All brand names, logos, and trademarks are the property of their respective owners.