|
| 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 | + |
| 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 | + |
| 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 | + |
| 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 | + |
| 79 | + |
| 80 | +That's it! |
| 81 | +You are now logged in securely. |
0 commit comments