|
1 | | -# Creating a new MFA method: Frontend |
| 1 | +# Creating a new MFA method: Front-end |
2 | 2 |
|
3 | 3 | ## Introduction |
4 | 4 |
|
5 | 5 | The MFA module provides a clear path for creating additional authentication methods. In this document we'll cover how to |
6 | 6 | implement the front-end portion of the required code, using the Basic Math method as an example. Some prior experience |
7 | 7 | with React / Redux is recommended. |
8 | 8 |
|
9 | | -The front-end components of MFA make use of [`react-injector`](https://github.com/silverstripe/react-injector/) (Injector) to allow sharing of React components and Redux |
10 | | -reducers between separate JS bundles. You can find more documentation on the Injector API in the [SilverStripe docs](https://docs.silverstripe.org/en/4/developer_guides/customising_the_admin_interface/reactjs_redux_and_graphql/#the-injector-api). |
| 9 | +The front-end components of MFA make use of [`react-injector`](https://github.com/silverstripe/react-injector/) |
| 10 | +(Injector) to allow sharing of React components and Redux reducers between separate JS bundles. You can find more |
| 11 | +documentation on the Injector API in the [SilverStripe docs](https://docs.silverstripe.org/en/4/developer_guides/customising_the_admin_interface/reactjs_redux_and_graphql/#the-injector-api). |
11 | 12 |
|
12 | 13 | You'll find it easiest to get up and running by matching the NPM dependencies and Webpack configuration used in the TOTP |
13 | | -and WebAuthn modules, with a single entry point that handles registering your components with Injector. |
| 14 | +and WebAuthn modules, with a single entry point that handles registering your components with Injector. We also suggest |
| 15 | +making use of the i18n library, exposed to components as `window.ss.i18n`, and shown in the examples below. |
14 | 16 |
|
15 | 17 | ## Create components |
16 | 18 |
|
@@ -85,13 +87,15 @@ export default Register; |
85 | 87 | Your verification component will look similar to your registration one - it should accept the following props: |
86 | 88 |
|
87 | 89 | - `onCompleteVerification`: A callback that should be invoked when the user has completed the challenge presented, with |
88 | | - any data that your `VerifyHandlerInterface::verify()` implementation needs to confirm the user's identity. |
| 90 | + any data that your `VerifyHandlerInterface::verify()` implementation needs to confirm the user's identity. **NOTE:** |
| 91 | + It is _imperative_ that your backend code is involved in the verification process, as providing secrets to the browser |
| 92 | + or otherwise relying solely on it to approve the authentication can result in significant security flaws. |
89 | 93 | - `moreOptionsControl`: A React component to render in your UI, which presents a button for users to pick a different |
90 | 94 | method to authenticate with. We recommend referencing the layout of the TOTP / WebAuthn implementations. |
91 | 95 | - Any data you return from your `VerifyHandlerInterface::start()` implementation will also be provided to the |
92 | 96 | component as props. For example, the WebAuthn module sends a challenge for the security key to sign. |
93 | 97 |
|
94 | | -A Register component for Basic Math might look like this: |
| 98 | +A Verify component for Basic Math might look like this: |
95 | 99 |
|
96 | 100 | ```jsx |
97 | 101 | import React, { Component } from 'react'; |
@@ -126,7 +130,7 @@ class BasicMathVerify extends Component { |
126 | 130 | if (!numbers) { |
127 | 131 | return ( |
128 | 132 | <div> |
129 | | - <h3>Loading...</h1> |
| 133 | + <h3>{i18n._t('BasicMathLogin.LOADING', 'Loading...')}</h3> |
130 | 134 | { moreOptionsControl } |
131 | 135 | </div> |
132 | 136 | ); |
|
0 commit comments