Skip to content

Commit 6bb1bc8

Browse files
committed
1 parent 369c8e4 commit 6bb1bc8

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

adminforth/documentation/docs/tutorial/08-Plugins/02-TwoFactorsAuth.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,52 @@ plugins: [
227227
228228
So such users will have suggestion to setup 2FA, but will be able to skip it with "Skip for now" button.
229229
230+
## Calling 2FA modal from backend
231+
If you wan't to call 2FA verification modal from the backend for verification, you can use
230232
231-
## Step-Up MFA (Two-Factor re-authentication on critical operations)
233+
```ts
234+
t2fa.verifyAuto(adminUser);
235+
```
236+
This method opens 2FA verification modal at the frontend and then returns verification result.
237+
238+
Here is an example:
239+
240+
```ts title="./api.ts"
241+
//diff-add
242+
app.get(`${admin.config.baseUrl}/api/test2faCall/`,
243+
//diff-add
244+
admin.express.authorize(
245+
//diff-add
246+
async (_req: IAdminUserExpressRequest, res: Response) => {
247+
//diff-add
248+
const { adminUser } = _req;
249+
//diff-add
250+
//diff-add
251+
const t2fa = admin.getPluginByClassName('TwoFactorsAuthPlugin');
252+
//diff-add
253+
const verifyResult = await t2fa.verifyAuto(adminUser);
254+
//diff-add
255+
if (verifyResult.ok) {
256+
//diff-add
257+
//some critical action
258+
//diff-add
259+
res.json({ ok: "true" });
260+
//diff-add
261+
}
262+
//diff-add
263+
res.json({ok: "false", message: "Verification failed"})
264+
//diff-add
265+
}
266+
//diff-add
267+
)
268+
//diff-add
269+
);
270+
```
271+
272+
Under the hood, this metod uses websocket.
273+
274+
## Manual Step-Up MFA (Two-Factor re-authentication on critical operations)
275+
But if you websocket doesn't work in you application, or you wan't to perform verification manually, here are manual verification examples
232276
233277
### Request 2FA on custom Actions
234278

0 commit comments

Comments
 (0)