Skip to content
cjhaas blog

Basically a place that Chris can post solutions to problems so he can easily find them later

cjhaas blog

Basically a place that Chris can post solutions to problems so he can easily find them later

Adding two-factor authentication to Drupal 8 using Google Authenticator

Posted on February 14, 2017 By [email protected]

The instructions are based on Drupal 8.2.6. Parts, such as upgrade random_compat, might not be applicable in later versions. I can’t make any guarantees about running these in earlier versions.

Install Christian Riesen’s OTP (One Time Password)

From the drupal site root run:

composer require christian-riesen/otp

Upgrade random compat

Drupal 8.2 installs random_compat 1.x but we need 2.x. A patch was applied in 8.2.6 but for some reason we need to force the upgrade.

composer require paragonie/random_compat:~2.0

Install the PHP Encryption

From the drupal site root run:

composer require defuse/php-encryption

Install Two-Factor module

drush dl tfa
drush en tfa --yes

If the second command freaks out try running it with sudo

Install Real AES module

drush dl real_aes
drush en real_aes --yes

Install Google Authenticator login module

drush dl ga_login
drush en ga_login --yes

Create a key

From your browser go to the following Drupal admin URL and click the add button:

/admin/config/system/keys

(If your site is example.com then go to example.com/admin/config/system/keys)

  1. Give the key a memorable name
  2. Set the key type to Encryption
  3. Set the key size to 256
  4. Run the following Linux command to generate a Base64 encoded random string:
    openssl rand -base64 32
  5. Use the value from the previous command for the key’s value.
  6. Check the Base64-encoded checkbox
  7. Press the save button

Create an Encryption Profile

From your browser go to the following Drupal admin URL and click the add button:

/admin/config/system/encryption/profiles
  1. Give the profile a memorable name
  2. Select Authenticated AES (Real AES) from the Encryption Method dropdown
  3. Select your key made in the section above for the Encryption Key
  4. Press Save

Enable TFA site-wide

From your browser go to the following Drupal admin URL and click the add button:

/admin/config/people/tfa
  1. Click the Enable TFA checkbox
  2. Select the Time-based method for validation
  3. Change the OTP QR Code Prefix to be something unique for your site (Very Important!!)
  4. Select the encryption profile that you created in the previous section
  5. This plugin is all-or-nothing, so all users must use TFA. However, if some users don’t want to use this you can set the value for Skip Validation to a high number such as 999999
  6. Optionally enable the TFA Trusted Browser setting if you understand the security risks
  7. Click the Save button

Configure your own profile for TFA

Edit your profile, click on Security and then on Set up application under TFA application. Follow the remaining steps which are just normal Google Authenticator setup.

Drupal Security google authenticatortfatwo-factor authentication

Post navigation

Previous post
Next post

Comments (2)

  1. Arijit Dutta says:
    July 2, 2019 at 5:39 am

    Savior!! Wonderful post.

    Reply
  2. Elvis Cubby says:
    October 16, 2019 at 6:34 pm

    Thanks Chris! Great post, you saved me.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Google open redirect
  • How to use AI to write code
  • Doctrine/Symfony MariaDB DSN connection string
  • Creating a portable copy of pdftotext from source
  • Gravity Forms shortcode getting extra line breaks when used with ACF

Recent Comments

  • jose luis on #2 – VB.Net iTextSharp Tutorial – Add an image to a document
  • Eliezer Castanon on iTextSharp slightly smarter text extraction strategy
  • javad on How to recompress images in a PDF using iTextSharp
  • MANOUS3784 on Flock is awesome
  • Sang on Flock is awesome

Archives

  • June 2026
  • October 2025
  • November 2023
  • September 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • December 2022
  • September 2022
  • April 2022
  • October 2021
  • September 2021
  • April 2021
  • January 2021
  • October 2020
  • August 2020
  • June 2020
  • May 2020
  • December 2019
  • November 2019
  • October 2019
  • July 2019
  • May 2019
  • December 2018
  • October 2018
  • July 2018
  • November 2017
  • October 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • September 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • November 2013
  • May 2013
  • April 2013
  • March 2013
  • January 2013
  • November 2012
  • October 2012
  • July 2012
  • March 2012
  • January 2012
  • October 2011
  • September 2011
  • July 2011
  • February 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • June 2010
  • April 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009

Categories

  • Accessibility
  • Advanced Custom Fields
  • Authorize.Net
  • BWP Minify
  • Composer
  • Crappy Google Search Results of the Day
  • CSS
  • Doctrine
  • Drupal
  • Drush
  • Elasticsearch
  • Fun links of the day
  • Google Analytics
  • Gravity Forms
  • HHVM
  • HTML
  • iTextSharp
  • JavaScript
  • Linux
  • mysql
  • nginx
  • Optimization
  • PDF
  • PdfPTable
  • PHP
  • Plugins
  • Ramblings
  • Random things I learned
  • Redis
  • Security
  • simplesamlphp
  • SQL Server
  • SSH
  • SSL/TLS/HTTPS
  • Stack Overflow
  • SVG
  • Symfony
  • Synology
  • Uncategorized
  • Unicode
  • Varnish
  • Vendi Best Practice
  • VIP
  • Weird Google Search Results
  • Windows
  • WordPress
  • WP-CLI

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2026 cjhaas blog | WordPress Theme by SuperbThemes