Skip to content

Commit 1d75a07

Browse files
committed
added totp pages - security, install tutorial
Signed-off-by: bidi <bidi@apidemia.com>
1 parent e35951b commit 1d75a07

3 files changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Time-based One-Time Password (TOTP)
2+
3+
A **Time-based One-Time Password (TOTP)** is a security algorithm used as part of **two-factor authentication (2FA)** to protect against account attacks.
4+
5+
The mechanism is integrated into [dot-totp](https://github.com/dotkernel/dot-totp) to enhance security by requiring both a **password** and **an additional one-time code**.
6+
Our implementation follows the industry standard of using an Authenticator app to generate temporary, unique 6-digit codes that change every 30 seconds.
7+
8+
## 2FA with TOTP Flow
9+
10+
Below is a simplified flow for the 2FA with a TOTP mechanism.
11+
12+
```mermaid
13+
sequenceDiagram
14+
participant U as 👤 User
15+
participant A as 📱 Authenticator App
16+
participant S as 🖥 Server
17+
18+
U->>S: 1. Enter username + password
19+
S->>S: 2. Verify credentials
20+
21+
S-->>U: 3. Request TOTP code
22+
23+
A->>U: 4. Display TOTP (time-based)
24+
U->>S: 5. Submit TOTP code
25+
26+
S->>S: 6. Validate (shared secret + time)
27+
28+
S-->>U: 7. ✅ Access granted
29+
```
30+
31+
## Next Steps
32+
33+
[Install 2FA with dot-totp](../configuring-2fa-with-totp.md).
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Installing dot-totp into Dotkernel Admin
2+
3+
If you haven't already, install [Dotkernel Admin](https://github.com/dotkernel/admin).
4+
5+
> The installation steps listed below should work similarly in any middleware-based application.
6+
7+
The first step is to include the package in your project by running this command:
8+
9+
```shell
10+
composer require dotkernel/dot-totp
11+
```
12+
13+
We will follow the Dotkernel file structure and create the files in the list below.
14+
If you follow the links from the [main totp integration example](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp), you can download the files and add them to your codebase.
15+
16+
- [src/Admin/src/Form/RecoveryForm.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Form/RecoveryForm.php)
17+
- [src/Admin/src/Form/TotpForm.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Form/TotpForm.php)
18+
- [src/Admin/src/Handler/Account/GetDisableTotpFormHandler.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Handler/Account/GetDisableTotpFormHandler.php)
19+
- [src/Admin/src/Handler/Account/GetEnableTotpFormHandler.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Handler/Account/GetEnableTotpFormHandler.php)
20+
- [src/Admin/src/Handler/Account/GetRecoveryFormHandler.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Handler/Account/GetRecoveryFormHandler.php)
21+
- [src/Admin/src/Handler/Account/GetTotpHandler.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Handler/Account/GetTotpHandler.php)
22+
- [src/Admin/src/Handler/Account/PostDisableTotpHandler.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Handler/Account/PostDisableTotpHandler.php)
23+
- [src/Admin/src/Handler/Account/PostEnableTotpHandler.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Handler/Account/PostEnableTotpHandler.php)
24+
- [src/Admin/src/Handler/Account/PostValidateRecoveryHandler.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Handler/Account/PostValidateRecoveryHandler.php)
25+
- [src/Admin/src/Handler/Account/PostValidateTotpHandler.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/src/Handler/Account/PostValidateTotpHandler.php)
26+
- [src/Admin/templates/admin/recovery-form.html.twig](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Admin/templates/admin/recovery-form.html.twig)
27+
- [src/App/src/Middleware/CancelUrlMiddleware.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/App/src/Middleware/CancelUrlMiddleware.php)
28+
- [src/App/src/Middleware/TotpMiddleware.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/App/src/Middleware/TotpMiddleware.php)
29+
30+
You can use the trait at [src/Core/src/App/src/Entity/TotpTrait.php](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/src/Core/src/App/src/Entity/TotpTrait.php) in any entity where you need 2FA.
31+
32+
> Make sure to migrate the new columns `totpSecret`, `totp_enabled` and `recovery_codes` in your entity.
33+
34+
There are still some code snippets in the [_misc](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp) folder:
35+
36+
- [the enable/disable 2FA button](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/_misc/totp-append-view-account.html.twig) should be used in the `view-account.html.twig` file or in a new page.
37+
- [the routes updates](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/_misc/totp-append-routes.php) must be added in the `src/Admin/src/RoutesDelegator.php` file.
38+
- [the pipeline updates](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/_misc/totp-append-Pipeline.php) must be added in the `config/pipeline.php` file after `$app->pipe(AuthMiddleware::class);`.
39+
- [the ConfigProvider updates](https://github.com/dotkernel/admin-documentation/tree/main/code_examples/totp/_misc/totp-append-ConfigProvider.php) must be added in the `src/Admin/src/ConfigProvider.php` file.
40+
41+
## Dot-totp in Action
42+
43+
Once you have `dot-totp` implemented, you can activate the feature in your admin accounts.
44+
If you navigate to your profile from the top-right image in Dotkernel Admin, you should see this box.
45+
46+
![Dotkernel Admin File Structure!](https://docs.dotkernel.org/img/admin/v7/install-totp/profile-totp-deactivated.jpg)
47+
48+
Simply click on 'Enable TOTP' to begin the activation process.
49+
50+
> We blurred out the QR code and recovery codes for this tutorial.
51+
> You will receive dynamically generated versions that will be fully visible to you.
52+
53+
> You will need to have an Authenticator app installed on your mobile device.
54+
55+
![Dotkernel Admin File Structure!](https://docs.dotkernel.org/img/admin/v7/install-totp/totp-activate-qr.jpg)
56+
57+
Follow the instructions on the screen:
58+
59+
- Scan the QR code with your mobile device.
60+
- Enter the 6-digit code it generates on your mobile device.
61+
62+
> The code refreshes every 30 seconds.
63+
64+
The TOPT activation flow will list several recovery codes you can use if your mobile device isn't available.
65+
66+
![Dotkernel Admin File Structure!](https://docs.dotkernel.org/img/admin/v7/install-totp/totp-recovery-codes.jpg)
67+
68+
> Each recovery code is usable only once.
69+
70+
> Save the recovery codes in a secure location.
71+
72+
If the code is valid, you will be logged in, and TOTP will be activated for your account.
73+
74+
Whenever you need to log into the account, you will start by entering your username and password, like before.
75+
Since TOTP is activated, you will need to also submit the code from your Authenticator app.
76+
Alternatively, you can submit a recovery code.
77+
78+
![Dotkernel Admin File Structure!](https://docs.dotkernel.org/img/admin/v7/install-totp/totp-ask-code.jpg)
79+
80+
That's it!
81+
You are now logged in securely.

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ nav:
3535
- "Set Up CSRF": v7/how-to/csrf.md
3636
- Security:
3737
- "Basic Security": v7/security/basic-security.md
38+
- "Two Factor Authorization with Time-based One-Time Password": v7/security/2fa-with-totp.md
3839
- Tutorials:
3940
- "Creating a book module using DotMaker": v7/tutorials/create-book-module-via-dot-maker.md
41+
- "Installing dot-totp": v7/tutorials/install-dot-totp.md
4042
- v6:
4143
- Introduction: v6/introduction/introduction.md
4244
- Overview:

0 commit comments

Comments
 (0)