DEV Community

Cover image for Umbraco 10 - punkTwoFactor Authentication Package
Gareth Wright
Gareth Wright

Posted on • Edited on

Umbraco 10 - punkTwoFactor Authentication Package

I needed to easily rollout Two Factor authentication on Umbraco, so I decided to take the Umbraco Documentation and create a package to make installation simple for Umbraco 9.5+ sites.

I've changed some of the code to be extensions on the IUmbracoBuilder rather than a composer, added the manual key to the dialog modal and added configuration for each environment.

Nuget

https://www.nuget.org/packages/punkTwoFactor/

Install-Package punkTwoFactor
Enter fullscreen mode Exit fullscreen mode

Installation

Install the nuget package, then add the following section to your appsettings.json:

"punkTwoFactor": {
    "ProviderName": "Two Factor Authentication",
    "Issuer": "Two Factor Authentication - Dev",
    "BackOfficeView": "..\\App_Plugins\\punkTwoFactor\\twoFactorProviderGoogleAuthenticator.html"
  }
Enter fullscreen mode Exit fullscreen mode

Add the following code block within your ConfigureServices section above the Umbraco setup:

services.Configure<TwoFactorConfig>(_config.GetSection("punkTwoFactor"));
TwoFactorConfig twoFactorConfiguration = new();
_config.GetSection("punkTwoFactor").Bind(twoFactorConfiguration);
Enter fullscreen mode Exit fullscreen mode

Now add the "AddBackOfficeTwoFactorAuthentication" extension to the Umbraco setup.

services
    .AddUmbraco(_env, _config)
    .AddBackOffice()
    .AddWebsite()            
    .AddBackOfficeTwoFactorAuthentication(twoFactorConfiguration)
    .Build();
Enter fullscreen mode Exit fullscreen mode

Usage

Click on your profile picture in Umbraco:
Header

Click the Configure Two Factor button:
Configure Two-Factor

Then click Enable:
Enable Button

You'll then see the familar QR code, with the additional Manual Input key:
QR Code

Once you add this QR code to your authenticator, you can enter the code and you're good!

Enabled

You'll now be configured to use Two Factor Authentication on your account! :)

Login

GitHub

https://github.com/garpunkal/punkTwoFactor

Contact

If you need any help, give me a shout on twitter.

Top comments (0)