Skip to content

Commit 30bc22e

Browse files
eshanrnhgitbook-bot
authored andcommitted
GITBOOK-26: Fixed code format
1 parent 67c085f commit 30bc22e

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

15/umbraco-cms/reference/security/two-factor-authentication.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ Umbraco controls how the UI is for user login and user edits, but will still nee
204204
In the following example, we will use the [GoogleAuthenticator NuGet Package](https://www.nuget.org/packages/GoogleAuthenticator/). Despite the name, this package works for both Google and Microsoft authenticator apps. It can be used to generate the QR code needed to activate the app for the website.
205205

206206
{% code title="TwoFactorAuthInfo.cs" lineNumbers="true" %}
207-
208207
```csharp
209208
using System.Runtime.Serialization;
210209
using Google.Authenticator;
@@ -289,15 +288,13 @@ public class UmbracoUserAppAuthenticator : ITwoFactorProvider
289288
public bool ValidateTwoFactorSetup(string secret, string token) => ValidateTwoFactorPIN(secret, token);
290289
}
291290
```
292-
293291
{% endcode %}
294292

295293
First, we create a model with the information required to set up the 2FA provider. Then we implement the `ITwoFactorProvider` with the use of the `TwoFactorAuthenticator` from the GoogleAuthenticator NuGet package.
296294

297295
Now we need to register the `UmbracoUserAppAuthenticator` implementation and the view to show to set up this provider. This can be done on the `IUmbracoBuilder` in your startup or a composer.
298296

299297
{% code title="UmbracoAppAuthenticatorComposer.cs" lineNumbers="true" %}
300-
301298
```csharp
302299
using Umbraco.Cms.Core.Composing;
303300
using Umbraco.Cms.Core.Security;
@@ -314,13 +311,11 @@ public class UmbracoAppAuthenticatorComposer : IComposer
314311
}
315312
}
316313
```
317-
318314
{% endcode %}
319315

320316
The last thing required is to register the provider in the Backoffice client so that the user can enable it. This can be done in a `umbraco-package.json` file.
321317

322-
{% code title="~/App_Plugins/TwoFactorProviders/umbraco-package.json" lineNumbers="true" %
323-
}
318+
{% code title="~/App_Plugins/TwoFactorProviders/umbraco-package.json" lineNumbers="true" %}
324319
```json
325320
{
326321
"$schema": "../../umbraco-package-schema.json",
@@ -339,7 +334,6 @@ The last thing required is to register the provider in the Backoffice client so
339334
]
340335
}
341336
```
342-
343337
{% endcode %}
344338

345339
At this point, the 2FA is active, but no users have set up 2FA yet.
@@ -392,7 +386,7 @@ The 2FA experience can be customized in Umbraco. This can be done by creating a
392386

393387
The following examples show how to customize the 2FA activation screen and the 2FA login screen.
394388

395-
The examples are using the [Lit](https://lit.dev/) library to create custom elements. This is the recommended way of creating custom elements in Umbraco. Lit is a light-weight library that augments the [Custom Elements API](https://developer.mozilla.org/en-US/docs/Web/API/Web\_components/Using\_custom\_elements) to provide a declarative, performant, and interoperable way to create web components.
389+
The examples are using the [Lit](https://lit.dev/) library to create custom elements. This is the recommended way of creating custom elements in Umbraco. Lit is a light-weight library that augments the [Custom Elements API](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements) to provide a declarative, performant, and interoperable way to create web components.
396390

397391
The examples are using the `@umbraco-cms/backoffice` package to get access to the Umbraco backoffice components and services. This package is included in Umbraco and can be used to create custom elements that look and feel like the rest of the Umbraco backoffice.
398392

@@ -405,7 +399,6 @@ The 2FA activation screen can be customized. This should be done if you have a 2
405399
To customize the 2FA activation screen, you need to create a JavaScript module. The module should export a default custom element to be used in the activation screen. This module should be placed in the `App_Plugins/TwoFactorProviders` folder.
406400

407401
{% code title="~/App_Plugins/TwoFactorProviders/2fa-activation.js" lineNumbers="true" %}
408-
409402
```javascript
410403
import { UserService } from '@umbraco-cms/backoffice/external/backend-api';
411404
import { css, html } from '@umbraco-cms/backoffice/external/lit';
@@ -613,15 +606,13 @@ export default class My2faActivationElement extends UmbLitElement {
613606

614607
customElements.define('my-2fa-activation', My2faActivationElement);
615608
```
616-
617609
{% endcode %}
618610
619611
This module will show a QR code and an input field for the user to enter the code from the authenticator app. When the user submits the form, the code will be sent to the server to validate. If the code is correct, the provider will be enabled.
620612
621613
To replace the default activation screen with the custom view, you need to register the element in the `umbraco-package.json` file that you created before. The final form of the file should look like this:
622614
623615
{% code title="~/App_Plugins/TwoFactorProviders/umbraco-package.json" lineNumbers="true" %}
624-
625616
```json
626617
{
627618
"$schema": "../../umbraco-package-schema.json",
@@ -641,7 +632,6 @@ To replace the default activation screen with the custom view, you need to regis
641632
]
642633
}
643634
```
644-
645635
{% endcode %}
646636
647637
### Customizing the login screen
@@ -660,7 +650,7 @@ You can use the following code as a starting point. This will give you a view lo
660650
661651
![Custom 2FA login](images/2fa-login-custom-view.png)
662652
663-
The following code is an example of a custom 2FA login screen using [Lit](https://lit.dev/). This is the recommended way of creating a custom 2FA login screen. Lit is a light-weight library that augments the [Custom Elements API](https://developer.mozilla.org/en-US/docs/Web/API/Web\_components/Using\_custom\_elements) to provide a declarative, performant, and interoperable way to create web components.
653+
The following code is an example of a custom 2FA login screen using [Lit](https://lit.dev/). This is the recommended way of creating a custom 2FA login screen. Lit is a light-weight library that augments the [Custom Elements API](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements) to provide a declarative, performant, and interoperable way to create web components.
664654
665655
The element registers two properties: providers and returnPath. These properties are used to render the view. The providers property is an array of strings, where each string is the name of a 2FA provider. The returnPath is the path to redirect to after a successful login. Both supplied by the login screen automatically.
666656

0 commit comments

Comments
 (0)