Skip to content

Commit 211e6f4

Browse files
vigneshshanmugammergify[bot]
authored andcommitted
[Synthetics]: fix MFA totp method for browser monitors (#4581)
(cherry picked from commit 083cf27) # Conflicts: # docs/en/serverless/synthetics/synthetics-mfa.asciidoc
1 parent f955527 commit 211e6f4

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

docs/en/observability/synthetics-mfa.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { journey, step, mfa} from '@elastic/synthetics';
4141
journey('MFA Test', ({ page, params }) => {
4242
step('Login using TOTP token', async () => {
4343
// login using username and pass and go to 2FA in next page
44-
const token = mfa.token(params.MFA_GH_SECRET);
44+
const token = mfa.totp(params.MFA_SECRET);
4545
await page.getByPlaceholder("token-input").fill(token)
4646
});
4747
});
@@ -51,12 +51,12 @@ For monitors created in the Synthetics UI using the Script editor, the `mfa` obj
5151

5252
```ts
5353
step('Login using 2FA', async () => {
54-
const token = mfa.token(params.MFA_GH_SECRET);
54+
const token = mfa.totp(params.MFA_SECRET);
5555
await page.getByPlaceholder("token-input").fill(token)
5656
});
5757
```
5858

5959
[NOTE]
6060
====
61-
`params.MFA_GH_SECRET` would be the encoded secret that was used for registering the Synthetics Authentication in your web application.
61+
`params.MFA_SECRET` would be the encoded secret that was used for registering the Synthetics Authentication in your web application.
6262
====
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[[observability-synthetics-mfa]]
2+
= Multi-factor Authentication (MFA) for browser monitors
3+
4+
++++
5+
<titleabbrev>Multifactor Authentication for browser monitors</titleabbrev>
6+
++++
7+
8+
Multi-factor Authentication (MFA) adds an essential layer of security to
9+
applications login processes, protecting against unauthorized access. A very
10+
common use case in Synthetics is testing user journeys involving websites
11+
protected by MFA.
12+
13+
Synthetics supports testing websites secured by Time-based One-Time Password
14+
(TOTP), a common MFA method that provides short-lived one-time tokens to
15+
enhance security.
16+
17+
[discrete]
18+
[[observability-synthetics-mfa-configuring-totp-for-mfa]]
19+
== Configuring TOTP for MFA
20+
21+
To test a browser journey that uses TOTP for MFA, first configure the
22+
Synthetics authenticator token in the target application. To do this, generate a One-Time
23+
Password (OTP) using the Synthetics CLI; refer to <<observability-synthetics-command-reference,`@elastic/synthetics totp <secret>`>>.
24+
25+
[source,sh]
26+
----
27+
npx @elastic/synthetics totp <secret>
28+
29+
// prints
30+
OTP Token: 123456
31+
----
32+
33+
[discrete]
34+
[[observability-synthetics-mfa-applying-the-totp-token-in-browser-journeys]]
35+
== Applying the TOTP Token in Browser Journeys
36+
37+
Once the Synthetics TOTP Authentication is configured in your application, you can now use the OTP token in the synthetics browser
38+
journeys using the `mfa` object imported from `@elastic/synthetics`.
39+
40+
[source,ts]
41+
----
42+
import { journey, step, mfa } from "@elastic/synthetics";
43+
44+
journey("MFA Test", ({ page, params }) => {
45+
step("Login using TOTP token", async () => {
46+
// login using username and pass and go to 2FA in next page
47+
const token = mfa.totp(params.MFA_SECRET);
48+
await page.getByPlaceholder("token-input").fill(token);
49+
});
50+
});
51+
----
52+
53+
For monitors created in the Synthetics UI using the Script editor, the `mfa` object can be accessed as shown below:
54+
55+
[source,ts]
56+
----
57+
step("Login using 2FA", async () => {
58+
const token = mfa.totp(params.MFA_SECRET);
59+
await page.getByPlaceholder("token-input").fill(token);
60+
});
61+
----
62+
63+
[NOTE]
64+
====
65+
`params.MFA_SECRET` would be the encoded secret that was used for registering the Synthetics Authentication in your web application.
66+
====

0 commit comments

Comments
 (0)