|
2 | 2 | mapped_urls: |
3 | 3 | - https://www.elastic.co/guide/en/observability/current/synthetics-mfa.html |
4 | 4 | - https://www.elastic.co/guide/en/serverless/current/observability-synthetics-mfa.html |
| 5 | + |
| 6 | +navigation_title: "Multi-factor Authentication" |
5 | 7 | --- |
6 | 8 |
|
7 | | -# Multi-factor Authentication (MFA) for browser monitors |
| 9 | +# Multi-factor Authentication (MFA) for browser monitors [synthetics-mfa] |
| 10 | + |
| 11 | + |
| 12 | +Multi-factor Authentication (MFA) adds an essential layer of security to applications login processes, protecting against unauthorized access. A very common use case in Synthetics is testing user journeys involving websites protected by MFA. |
| 13 | + |
| 14 | +Synthetics supports testing websites secured by Time-based One-Time Password (TOTP), a common MFA method that provides short-lived one-time tokens to enhance security. |
| 15 | + |
| 16 | + |
| 17 | +## Configuring TOTP for MFA [configuring_totp_for_mfa] |
| 18 | + |
| 19 | +To test a browser journey that uses TOTP for MFA, first configure the Synthetics authenticator token in the target application. To do this, generate a One-Time Password (OTP) using the Synthetics CLI; refer to [`@elastic/synthetics totp <secret>`](../../../solutions/observability/apps/use-synthetics-cli.md). |
| 20 | + |
| 21 | +```sh |
| 22 | +npx @elastic/synthetics totp <secret> |
| 23 | + |
| 24 | +// prints |
| 25 | +OTP Token: 123456 |
| 26 | +``` |
| 27 | + |
| 28 | + |
| 29 | +## Applying the TOTP Token in Browser Journeys [applying_the_totp_token_in_browser_journeys] |
| 30 | + |
| 31 | +Once the Synthetics TOTP Authentication is configured in your application, you can now use the OTP token in the synthetics browser journeys using the `mfa` object imported from `@elastic/synthetics`. |
| 32 | + |
| 33 | +```ts |
| 34 | +import { journey, step, mfa} from '@elastic/synthetics'; |
| 35 | + |
| 36 | +journey('MFA Test', ({ page, params }) => { |
| 37 | + step('Login using TOTP token', async () => { |
| 38 | + // login using username and pass and go to 2FA in next page |
| 39 | + const token = mfa.totp(params.MFA_SECRET); |
| 40 | + await page.getByPlaceholder("token-input").fill(token) |
| 41 | + }); |
| 42 | +}); |
| 43 | +``` |
| 44 | + |
| 45 | +For monitors created in the Synthetics UI using the Script editor, the `mfa` object can be accessed as shown below: |
8 | 46 |
|
9 | | -% What needs to be done: Align serverless/stateful |
| 47 | +```ts |
| 48 | +step('Login using 2FA', async () => { |
| 49 | + const token = mfa.totp(params.MFA_SECRET); |
| 50 | + await page.getByPlaceholder("token-input").fill(token) |
| 51 | +}); |
| 52 | +``` |
10 | 53 |
|
11 | | -% Use migrated content from existing pages that map to this page: |
| 54 | +::::{note} |
| 55 | +`params.MFA_SECRET` would be the encoded secret that was used for registering the Synthetics Authentication in your web application. |
12 | 56 |
|
13 | | -% - [ ] ./raw-migrated-files/observability-docs/observability/synthetics-mfa.md |
14 | | -% - [ ] ./raw-migrated-files/docs-content/serverless/observability-synthetics-mfa.md |
| 57 | +:::: |
0 commit comments